Skip to content

Commit 823c6d5

Browse files
johnkeepinggitster
authored andcommitted
fetch: don't try to update unfetched tracking refs
Since commit f269048 (fetch: opportunistically update tracking refs, 2013-05-11) we update tracking refs opportunistically when fetching remote branches. However, if there is a configured non-pattern refspec that does not match any of the refspecs given on the command line then a fatal error occurs. Fix this by setting the "missing_ok" flag when calling get_fetch_map. Test-added-by: Jeff King <[email protected]> Signed-off-by: John Keeping <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f269048 commit 823c6d5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

builtin/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static struct ref *get_ref_map(struct transport *transport,
183183
old_tail = tail;
184184
for (i = 0; i < transport->remote->fetch_refspec_nr; i++)
185185
get_fetch_map(ref_map, &transport->remote->fetch[i],
186-
&tail, 0);
186+
&tail, 1);
187187
for (rm = *old_tail; rm; rm = rm->next)
188188
rm->fetch_head_status = FETCH_HEAD_IGNORE;
189189
} else {

t/t5510-fetch.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,22 @@ test_expect_success 'configured fetch updates tracking' '
422422
)
423423
'
424424

425+
test_expect_success 'non-matching refspecs do not confuse tracking update' '
426+
cd "$D" &&
427+
git update-ref refs/odd/location HEAD &&
428+
(
429+
cd three &&
430+
git update-ref refs/remotes/origin/master base-origin-master &&
431+
git config --add remote.origin.fetch \
432+
refs/odd/location:refs/remotes/origin/odd &&
433+
o=$(git rev-parse --verify refs/remotes/origin/master) &&
434+
git fetch origin master &&
435+
n=$(git rev-parse --verify refs/remotes/origin/master) &&
436+
test "$o" != "$n" &&
437+
test_must_fail git rev-parse --verify refs/remotes/origin/odd
438+
)
439+
'
440+
425441
test_expect_success 'pushing nonexistent branch by mistake should not segv' '
426442
427443
cd "$D" &&

0 commit comments

Comments
 (0)