Since 9badf97c4 (remote: allow resetting url list), we reset the remote URL if the provided URL is empty. This means any caller of `remotes_remote_get()` would now get a NULL remote. The 'builtin/push.c' code, calls 'set_refspecs' before validating the remote. This worked earlier since we would get a remote, albeit with an empty URL. With the new changes, we get a NULL remote and this crashes. Do a simple fix by doing remote validation first and also add a test to validate the bug fix. Signed-off-by: Karthik Nayak <karthik.188@xxxxxxxxx> --- I noticed that this was breaking on master. We run tests on Git master for Gitaly at GitLab and I noticed a SEFAULT. I could also reproduce the bug by simply doing 'git push "" refs/heads/master' on master, next and seen. builtin/push.c | 7 ++++--- t/t5529-push-errors.sh | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/builtin/push.c b/builtin/push.c index 8260c6e46a..992f603de7 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -630,10 +630,8 @@ int cmd_push(int argc, const char **argv, const char *prefix) if (tags) refspec_append(&rs, "refs/tags/*"); - if (argc > 0) { + if (argc > 0) repo = argv[0]; - set_refspecs(argv + 1, argc - 1, repo); - } remote = pushremote_get(repo); if (!remote) { @@ -649,6 +647,9 @@ int cmd_push(int argc, const char **argv, const char *prefix) " git push <name>\n")); } + if (argc > 0) + set_refspecs(argv + 1, argc - 1, repo); + if (remote->mirror) flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE); diff --git a/t/t5529-push-errors.sh b/t/t5529-push-errors.sh index 0247137cb3..771f5f8ae8 100755 --- a/t/t5529-push-errors.sh +++ b/t/t5529-push-errors.sh @@ -2,6 +2,9 @@ test_description='detect some push errors early (before contacting remote)' +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME + TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh @@ -38,6 +41,11 @@ test_expect_success 'detect missing sha1 expressions early' ' test_cmp expect rp-ran ' +test_expect_success 'detect empty remote' ' + test_must_fail git push "" main 2> stderr && + grep "fatal: bad repository ''" stderr +' + test_expect_success 'detect ambiguous refs early' ' git branch foo && git tag foo && -- 2.45.1