]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fetch: no FETCH_HEAD display if --no-write-fetch-head
authorJonathan Tan <jonathantanmy@google.com>
Wed, 2 Sep 2020 21:05:39 +0000 (14:05 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 2 Sep 2020 21:26:55 +0000 (14:26 -0700)
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>
builtin/fetch.c
t/t0410-partial-clone.sh
t/t5510-fetch.sh

index 320ba9471dee36fc82eb36a1b24af0c1918cd9d0..c6c468925030b07d2f3b59c382669e0ce729ba88 100644 (file)
@@ -1023,11 +1023,17 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
                                rc |= update_local_ref(ref, what, rm, &note,
                                                       summary_width);
                                free(ref);
-                       } else
+                       } else if (write_fetch_head || dry_run) {
+                               /*
+                                * Display fetches written to FETCH_HEAD (or
+                                * would be written to FETCH_HEAD, if --dry-run
+                                * is set).
+                                */
                                format_display(&note, '*',
                                               *kind ? kind : "branch", NULL,
                                               *what ? what : "HEAD",
                                               "FETCH_HEAD", summary_width);
+                       }
                        if (note.len) {
                                if (verbosity >= 0 && !shown_url) {
                                        fprintf(stderr, _("From %.*s\n"),
index d681e90640398cc7abcd7a403a547cb61511b022..584a039b851dbbf727d35d469e7d05895f9ec4e8 100755 (executable)
@@ -183,7 +183,7 @@ test_expect_success 'missing CLI object, but promised, passes fsck' '
 '
 
 test_expect_success 'fetching of missing objects' '
-       rm -rf repo &&
+       rm -rf repo err &&
        test_create_repo server &&
        test_commit -C server foo &&
        git -C server repack -a -d --write-bitmap-index &&
@@ -194,7 +194,10 @@ test_expect_success 'fetching of missing objects' '
 
        git -C repo config core.repositoryformatversion 1 &&
        git -C repo config extensions.partialclone "origin" &&
-       git -C repo cat-file -p "$HASH" &&
+       git -C repo cat-file -p "$HASH" 2>err &&
+
+       # Ensure that no spurious FETCH_HEAD messages are written
+       ! grep FETCH_HEAD err &&
 
        # Ensure that the .promisor file is written, and check that its
        # associated packfile contains the object
index 2a1abe91f0fd34b7929aa636ab43542c6e45ea54..759aec9305e46abb7f5ab3da5a9b99a7502a7d3b 100755 (executable)
@@ -543,16 +543,18 @@ test_expect_success 'fetch into the current branch with --update-head-ok' '
 
 '
 
-test_expect_success 'fetch --dry-run does not touch FETCH_HEAD' '
-       rm -f .git/FETCH_HEAD &&
-       git fetch --dry-run . &&
-       ! test -f .git/FETCH_HEAD
+test_expect_success 'fetch --dry-run does not touch FETCH_HEAD, but still prints what would be written' '
+       rm -f .git/FETCH_HEAD err &&
+       git fetch --dry-run . 2>err &&
+       ! test -f .git/FETCH_HEAD &&
+       grep FETCH_HEAD err
 '
 
-test_expect_success '--no-write-fetch-head does not touch FETCH_HEAD' '
-       rm -f .git/FETCH_HEAD &&
-       git fetch --no-write-fetch-head . &&
-       ! test -f .git/FETCH_HEAD
+test_expect_success '--no-write-fetch-head does not touch FETCH_HEAD, and does not print what would be written' '
+       rm -f .git/FETCH_HEAD err &&
+       git fetch --no-write-fetch-head . 2>err &&
+       ! test -f .git/FETCH_HEAD &&
+       ! grep FETCH_HEAD err
 '
 
 test_expect_success '--write-fetch-head gets defeated by --dry-run' '