Skip to content

Commit db3c293

Browse files
jonathantanmygitster
authored andcommitted
fetch: no FETCH_HEAD display if --no-write-fetch-head
887952b ("fetch: optionally allow disabling FETCH_HEAD update", 2020-08-18) introduced the ability to disable writing to FETCH_HEAD during fetch, but did not suppress the "<source> -> FETCH_HEAD" message when this ability is used. This message is misleading in this case, because FETCH_HEAD is not written. Also, because "fetch" is used to lazy-fetch missing objects in a partial clone, this significantly clutters up the output in that case since the objects to be fetched are potentially numerous. Therefore, suppress this message when --no-write-fetch-head is passed (but not when --dry-run is set). Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9dfa8db commit db3c293

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

builtin/fetch.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,11 +1023,17 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
10231023
rc |= update_local_ref(ref, what, rm, &note,
10241024
summary_width);
10251025
free(ref);
1026-
} else
1026+
} else if (write_fetch_head || dry_run) {
1027+
/*
1028+
* Display fetches written to FETCH_HEAD (or
1029+
* would be written to FETCH_HEAD, if --dry-run
1030+
* is set).
1031+
*/
10271032
format_display(&note, '*',
10281033
*kind ? kind : "branch", NULL,
10291034
*what ? what : "HEAD",
10301035
"FETCH_HEAD", summary_width);
1036+
}
10311037
if (note.len) {
10321038
if (verbosity >= 0 && !shown_url) {
10331039
fprintf(stderr, _("From %.*s\n"),

t/t0410-partial-clone.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ test_expect_success 'missing CLI object, but promised, passes fsck' '
183183
'
184184

185185
test_expect_success 'fetching of missing objects' '
186-
rm -rf repo &&
186+
rm -rf repo err &&
187187
test_create_repo server &&
188188
test_commit -C server foo &&
189189
git -C server repack -a -d --write-bitmap-index &&
@@ -194,7 +194,10 @@ test_expect_success 'fetching of missing objects' '
194194
195195
git -C repo config core.repositoryformatversion 1 &&
196196
git -C repo config extensions.partialclone "origin" &&
197-
git -C repo cat-file -p "$HASH" &&
197+
git -C repo cat-file -p "$HASH" 2>err &&
198+
199+
# Ensure that no spurious FETCH_HEAD messages are written
200+
! grep FETCH_HEAD err &&
198201
199202
# Ensure that the .promisor file is written, and check that its
200203
# associated packfile contains the object

t/t5510-fetch.sh

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -543,16 +543,18 @@ test_expect_success 'fetch into the current branch with --update-head-ok' '
543543
544544
'
545545

546-
test_expect_success 'fetch --dry-run does not touch FETCH_HEAD' '
547-
rm -f .git/FETCH_HEAD &&
548-
git fetch --dry-run . &&
549-
! test -f .git/FETCH_HEAD
546+
test_expect_success 'fetch --dry-run does not touch FETCH_HEAD, but still prints what would be written' '
547+
rm -f .git/FETCH_HEAD err &&
548+
git fetch --dry-run . 2>err &&
549+
! test -f .git/FETCH_HEAD &&
550+
grep FETCH_HEAD err
550551
'
551552

552-
test_expect_success '--no-write-fetch-head does not touch FETCH_HEAD' '
553-
rm -f .git/FETCH_HEAD &&
554-
git fetch --no-write-fetch-head . &&
555-
! test -f .git/FETCH_HEAD
553+
test_expect_success '--no-write-fetch-head does not touch FETCH_HEAD, and does not print what would be written' '
554+
rm -f .git/FETCH_HEAD err &&
555+
git fetch --no-write-fetch-head . 2>err &&
556+
! test -f .git/FETCH_HEAD &&
557+
! grep FETCH_HEAD err
556558
'
557559

558560
test_expect_success '--write-fetch-head gets defeated by --dry-run' '

0 commit comments

Comments
 (0)