]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/clone: suppress unexpected default branch advice
authorJustin Tobler <jltobler@gmail.com>
Tue, 25 Mar 2025 00:51:47 +0000 (19:51 -0500)
committerJunio C Hamano <gitster@pobox.com>
Tue, 25 Mar 2025 23:09:28 +0000 (16:09 -0700)
In 199f44cb2ead (builtin/clone: allow remote helpers to detect repo,
2024-02-27), clones started partially initializing the refdb before
executing the remote helpers by creating a HEAD file and "refs/"
directory. This has resulted in some scenarios where git-clone(1) now
prints the default branch name advice message where it previously did
not.

A side-effect of the HEAD file already existing, is that computation of
the default branch name is handled later in execution. This matters
because prior to 97abaab5f6 (refs: drop `git_default_branch_name()`,
2024-05-17), the default branch value would be computed during its first
execution and cached. Subsequent invocations would simply return the
cached value. Since the next `git_default_branch_name()` call site,
which is invoked through `guess_remote_head()`, is not configured to
suppress the advice message, computing the default branch name results
in the advice message being printed.

Configure `guess_remote_head()` to suppress the advice message,
restoring the previous behavior.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
Acked-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/clone.c
t/t5607-clone-bundle.sh

index f14229abf450c0ce829ce6163fda6549a3a1bcb9..baa76f88c37ea5741d91793a4924bc03401dc893 100644 (file)
@@ -450,7 +450,9 @@ static struct ref *wanted_peer_refs(struct clone_opts *opts,
                if (head)
                        tail_link_ref(head, &tail);
                if (option_single_branch)
-                       refs = to_free = guess_remote_head(head, refs, 0);
+                       refs = to_free =
+                               guess_remote_head(head, refs,
+                                                 REMOTE_GUESS_HEAD_QUIET);
        } else if (option_single_branch) {
                local_refs = NULL;
                tail = &local_refs;
@@ -1523,7 +1525,8 @@ int cmd_clone(int argc,
        }
 
        remote_head = find_ref_by_name(refs, "HEAD");
-       remote_head_points_at = guess_remote_head(remote_head, mapped_refs, 0);
+       remote_head_points_at = guess_remote_head(remote_head, mapped_refs,
+                                                 REMOTE_GUESS_HEAD_QUIET);
 
        if (option_branch) {
                our_head_points_at = find_remote_branch(mapped_refs, option_branch);
index 82e3621ec53edc2c98ecd485ecca0a65fe57f6ed..d709bea753044519f073c369f3c09de2a2da2794 100755 (executable)
@@ -211,4 +211,16 @@ test_expect_success 'git bundle v3 rejects unknown capabilities' '
        test_grep "unknown capability .unknown=silly." output
 '
 
+test_expect_success 'cloning bundle suppresses default branch name advice' '
+       test_when_finished "rm -rf bundle-repo clone-repo" &&
+
+       git init bundle-repo &&
+       git -C bundle-repo commit --allow-empty -m init &&
+       git -C bundle-repo bundle create repo.bundle --all &&
+       GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
+               git clone --single-branch bundle-repo/repo.bundle clone-repo 2>err &&
+
+       test_grep ! "hint: " err
+'
+
 test_done