Skip to content

Commit ca20a44

Browse files
committed
Merge branch 'jk/proto-v2-ref-prefix-fix'
"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()
2 parents b7f39a3 + 49ca2fb commit ca20a44

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

builtin/fetch.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,9 +1617,21 @@ static int do_fetch(struct transport *transport,
16171617
break;
16181618
}
16191619
}
1620-
} else if (transport->remote && transport->remote->fetch.nr)
1621-
refspec_ref_prefixes(&transport->remote->fetch,
1622-
&transport_ls_refs_options.ref_prefixes);
1620+
} else {
1621+
struct branch *branch = branch_get(NULL);
1622+
1623+
if (transport->remote->fetch.nr)
1624+
refspec_ref_prefixes(&transport->remote->fetch,
1625+
&transport_ls_refs_options.ref_prefixes);
1626+
if (branch_has_merge_config(branch) &&
1627+
!strcmp(branch->remote_name, transport->remote->name)) {
1628+
int i;
1629+
for (i = 0; i < branch->merge_nr; i++) {
1630+
strvec_push(&transport_ls_refs_options.ref_prefixes,
1631+
branch->merge[i]->src);
1632+
}
1633+
}
1634+
}
16231635

16241636
if (tags == TAGS_SET || tags == TAGS_DEFAULT) {
16251637
must_list_refs = 1;

t/t5520-pull.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,23 @@ test_expect_success 'fail if upstream branch does not exist' '
218218
test_cmp expect file
219219
'
220220

221+
test_expect_success 'fetch upstream branch even if refspec excludes it' '
222+
# the branch names are not important here except that
223+
# the first one must not be a prefix of the second,
224+
# since otherwise the ref-prefix protocol extension
225+
# would match both
226+
git branch in-refspec HEAD^ &&
227+
git branch not-in-refspec HEAD &&
228+
git init -b in-refspec downstream &&
229+
git -C downstream remote add -t in-refspec origin "file://$(pwd)/.git" &&
230+
git -C downstream config branch.in-refspec.remote origin &&
231+
git -C downstream config branch.in-refspec.merge refs/heads/not-in-refspec &&
232+
git -C downstream pull &&
233+
git rev-parse --verify not-in-refspec >expect &&
234+
git -C downstream rev-parse --verify HEAD >actual &&
235+
test_cmp expect actual
236+
'
237+
221238
test_expect_success 'fail if the index has unresolved entries' '
222239
git checkout -b third second^ &&
223240
test_when_finished "git checkout -f copy && git branch -D third" &&

0 commit comments

Comments
 (0)