]> git.ipfire.org Git - thirdparty/git.git/commitdiff
send-pack: fix push nego. when remote has refs
authorJonathan Tan <jonathantanmy@google.com>
Thu, 15 Jul 2021 17:44:31 +0000 (10:44 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 15 Jul 2021 18:58:52 +0000 (11:58 -0700)
Commit 477673d6f3 ("send-pack: support push negotiation", 2021-05-05)
did not test the case in which a remote advertises at least one ref. In
such a case, "remote_refs" in get_commons_through_negotiation() in
send-pack.c would also contain those refs with a zero ref->new_oid (in
addition to the refs being pushed with a nonzero ref->new_oid). Passing
them as negotiation tips to "git fetch" causes an error, so filter them
out.

(The exact error that would happen in "git fetch" in this case is a
segmentation fault, which is unwanted. This will be fixed in the
subsequent commit.)

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
send-pack.c
t/t5516-fetch-push.sh
t/t5549-fetch-push-http.sh

index 9cb9f716509b00ec394bb901b61d679eaa04045d..85945becf01b5fba8c3eb22c8a0df63183c3107e 100644 (file)
@@ -425,8 +425,10 @@ static void get_commons_through_negotiation(const char *url,
        child.no_stdin = 1;
        child.out = -1;
        strvec_pushl(&child.args, "fetch", "--negotiate-only", NULL);
-       for (ref = remote_refs; ref; ref = ref->next)
-               strvec_pushf(&child.args, "--negotiation-tip=%s", oid_to_hex(&ref->new_oid));
+       for (ref = remote_refs; ref; ref = ref->next) {
+               if (!is_null_oid(&ref->new_oid))
+                       strvec_pushf(&child.args, "--negotiation-tip=%s", oid_to_hex(&ref->new_oid));
+       }
        strvec_push(&child.args, url);
 
        if (start_command(&child))
index 0916f7630207be03ce2af25368146c1302375e27..4db8edd9c85ab1c4b6606f3548e82df3953ca04b 100755 (executable)
@@ -201,6 +201,7 @@ test_expect_success 'push with negotiation' '
        # Without negotiation
        mk_empty testrepo &&
        git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
+       test_commit -C testrepo unrelated_commit &&
        git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
        echo now pushing without negotiation &&
        GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 push testrepo refs/heads/main:refs/remotes/origin/main &&
@@ -210,6 +211,7 @@ test_expect_success 'push with negotiation' '
        rm event &&
        mk_empty testrepo &&
        git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
+       test_commit -C testrepo unrelated_commit &&
        git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
        GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main &&
        grep_wrote 2 event # 1 commit, 1 tree
@@ -219,6 +221,7 @@ test_expect_success 'push with negotiation proceeds anyway even if negotiation f
        rm event &&
        mk_empty testrepo &&
        git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
+       test_commit -C testrepo unrelated_commit &&
        git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
        GIT_TEST_PROTOCOL_VERSION=0 GIT_TRACE2_EVENT="$(pwd)/event" \
                git -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main 2>err &&
@@ -1767,5 +1770,4 @@ test_expect_success 'denyCurrentBranch and worktrees' '
        git -C cloned push origin HEAD:new-wt &&
        test_must_fail git -C cloned push --delete origin new-wt
 '
-
 test_done
index f50d58488115ea82b2322fe628715cad13c36a69..2cdebcb735633209e0bbdfa07bc4765657b77ffa 100755 (executable)
@@ -27,6 +27,7 @@ setup_client_and_server () {
        git init "$SERVER" &&
        test_when_finished 'rm -rf "$SERVER"' &&
        test_config -C "$SERVER" http.receivepack true &&
+       test_commit -C "$SERVER" unrelated_commit &&
        git -C client push "$URI" first_commit:refs/remotes/origin/first_commit &&
        git -C "$SERVER" config receive.hideRefs refs/remotes/origin/first_commit
 }