]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jk/proto-v2-ref-prefix-fix'
authorJunio C Hamano <gitster@pobox.com>
Thu, 15 Sep 2022 23:09:47 +0000 (16:09 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 15 Sep 2022 23:09:47 +0000 (16:09 -0700)
"git fetch" over protocol v2 sent an incorrect ref prefix request
to the server and made "git pull" with configured fetch refspec
that does not cover the remote branch to merge with fail, which has
been corrected.

* jk/proto-v2-ref-prefix-fix:
  fetch: add branch.*.merge to default ref-prefix extension
  fetch: stop checking for NULL transport->remote in do_fetch()

builtin/fetch.c
t/t5520-pull.sh

index e6b926dba23386c30ff24552b74a704847b6b32a..3aecbe4a3deb2555bf1f7cf198548be61ac942a8 100644 (file)
@@ -1617,9 +1617,21 @@ static int do_fetch(struct transport *transport,
                                break;
                        }
                }
-       } else if (transport->remote && transport->remote->fetch.nr)
-               refspec_ref_prefixes(&transport->remote->fetch,
-                                    &transport_ls_refs_options.ref_prefixes);
+       } else {
+               struct branch *branch = branch_get(NULL);
+
+               if (transport->remote->fetch.nr)
+                       refspec_ref_prefixes(&transport->remote->fetch,
+                                            &transport_ls_refs_options.ref_prefixes);
+               if (branch_has_merge_config(branch) &&
+                   !strcmp(branch->remote_name, transport->remote->name)) {
+                       int i;
+                       for (i = 0; i < branch->merge_nr; i++) {
+                               strvec_push(&transport_ls_refs_options.ref_prefixes,
+                                           branch->merge[i]->src);
+                       }
+               }
+       }
 
        if (tags == TAGS_SET || tags == TAGS_DEFAULT) {
                must_list_refs = 1;
index 081808009b2e74aa4cb81a768a15701dd4eca9d5..0b72112fb10759bb1d5e9de912ae1b2038df1d00 100755 (executable)
@@ -218,6 +218,23 @@ test_expect_success 'fail if upstream branch does not exist' '
        test_cmp expect file
 '
 
+test_expect_success 'fetch upstream branch even if refspec excludes it' '
+       # the branch names are not important here except that
+       # the first one must not be a prefix of the second,
+       # since otherwise the ref-prefix protocol extension
+       # would match both
+       git branch in-refspec HEAD^ &&
+       git branch not-in-refspec HEAD &&
+       git init -b in-refspec downstream &&
+       git -C downstream remote add -t in-refspec origin "file://$(pwd)/.git" &&
+       git -C downstream config branch.in-refspec.remote origin &&
+       git -C downstream config branch.in-refspec.merge refs/heads/not-in-refspec &&
+       git -C downstream pull &&
+       git rev-parse --verify not-in-refspec >expect &&
+       git -C downstream rev-parse --verify HEAD >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'fail if the index has unresolved entries' '
        git checkout -b third second^ &&
        test_when_finished "git checkout -f copy && git branch -D third" &&