Skip to content

Commit f12e03e

Browse files
jltoblergitster
authored andcommitted
builtin/clone: suppress unexpected default branch advice
In 199f44c (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 97abaab (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1a021af commit f12e03e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

builtin/clone.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,8 @@ int cmd_clone(int argc,
15231523
}
15241524

15251525
remote_head = find_ref_by_name(refs, "HEAD");
1526-
remote_head_points_at = guess_remote_head(remote_head, mapped_refs, 0);
1526+
remote_head_points_at = guess_remote_head(remote_head, mapped_refs,
1527+
REMOTE_GUESS_HEAD_QUIET);
15271528

15281529
if (option_branch) {
15291530
our_head_points_at = find_remote_branch(mapped_refs, option_branch);

t/t5607-clone-bundle.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,16 @@ test_expect_success 'git bundle v3 rejects unknown capabilities' '
211211
test_grep "unknown capability .unknown=silly." output
212212
'
213213

214+
test_expect_success 'cloning bundle suppresses default branch name advice' '
215+
test_when_finished "rm -rf bundle-repo clone-repo" &&
216+
217+
git init bundle-repo &&
218+
git -C bundle-repo commit --allow-empty -m init &&
219+
git -C bundle-repo bundle create repo.bundle --all &&
220+
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
221+
git clone bundle-repo/repo.bundle clone-repo 2>err &&
222+
223+
test_grep ! "hint: " err
224+
'
225+
214226
test_done

0 commit comments

Comments
 (0)