@matheusbsbs / matheus-bagliano / commits / db3c293ecd
Fork 0

fetch: no FETCH_HEAD display if --no-write-fetch-head

887952b8c6 ("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 <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Sep 2, 2020 at 14:05 UTC db3c293ecded67128b74a03f01e65c6799ff1116
3 files changed +22 -11
builtin/fetch.c
+7 -1
@@ -1023,11 +1023,17 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
1023 rc |= update_local_ref(ref, what, rm, &note,
1024 summary_width);
1025 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 + */
1032 format_display(&note, '*',
1033 *kind ? kind : "branch", NULL,
1034 *what ? what : "HEAD",
1035 "FETCH_HEAD", summary_width);
1036 + }
1037 if (note.len) {
1038 if (verbosity >= 0 && !shown_url) {
1039 fprintf(stderr, _("From %.*s\n"),
t/t0410-partial-clone.sh
+5 -2
@@ -183,7 +183,7 @@ test_expect_success 'missing CLI object, but promised, passes fsck' '
183 '
184
185 test_expect_success 'fetching of missing objects' '
186 - rm -rf repo &&
186 + rm -rf repo err &&
187 test_create_repo server &&
188 test_commit -C server foo &&
189 git -C server repack -a -d --write-bitmap-index &&
@@ -194,7 +194,10 @@ test_expect_success 'fetching of missing objects' '
194
195 git -C repo config core.repositoryformatversion 1 &&
196 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 &&
201
202 # Ensure that the .promisor file is written, and check that its
203 # associated packfile contains the object
t/t5510-fetch.sh
+10 -8
@@ -543,16 +543,18 @@ test_expect_success 'fetch into the current branch with --update-head-ok' '
543
544 '
545
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
551 '
552
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
558 '
559
560 test_expect_success '--write-fetch-head gets defeated by --dry-run' '