Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2022-07-08 02:59:35 +0300
committerJunio C Hamano <gitster@pobox.com>2022-07-08 06:57:54 +0300
commitcc8fcd1e1ac6ae2a7463b295ccb48e18c73f924a (patch)
tree31788c7aa588fecf4f1f5eda5f4219d7f0646bfc /t/t5702-protocol-v2.sh
parent3d8314f8d1e68d92f6c91d50e5a510db61355774 (diff)
clone: use remote branch if it matches default HEAD
Usually clone tries to use the same local HEAD as the remote (unless the user has given --branch explicitly). Even if the remote HEAD is detached or unborn, we can detect those situations with modern versions of Git. If the remote is too old to support the "unborn" extension (or it has been disabled via config), then we can't know the name of the remote's unborn HEAD, and we fall back whatever the local default branch name is configured to be. But that leads to one weird corner case. It's rare because it needs a number of factors: - the remote has an unborn HEAD - the remote is too old to support "unborn", or has disabled it - the remote has another branch "foo" - the local default branch name is "foo" In that case you end up with a local clone on an unborn "foo" branch, disconnected completely from the remote's "foo". This is rare in practice, but the result is quite confusing. When choosing "foo", we can double check whether the remote has such a name, and if so, start our local "foo" at the same spot, rather than making it unborn. Note that this causes a test failure in t5605, which is cloning from a bundle that doesn't contain HEAD (so it behaves like a remote that doesn't support "unborn"), but has a single "main" branch. That test expects that we end up in the weird "unborn main" case, where we don't actually check out the remote branch of the same name. Even though we have to update the test, this seems like an argument in favor of this patch: checking out main is what I'd expect from such a bundle. So this patch updates the test for the new behavior and adds an adjacent one that checks what the original was going for: if there's no HEAD and the bundle _doesn't_ have a branch that matches our local default name, then we end up with nothing checked out. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t5702-protocol-v2.sh')
-rwxr-xr-xt/t5702-protocol-v2.sh21
1 files changed, 21 insertions, 0 deletions
diff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh
index 2b3a78b842..5d42a355a8 100755
--- a/t/t5702-protocol-v2.sh
+++ b/t/t5702-protocol-v2.sh
@@ -288,6 +288,27 @@ test_expect_success 'bare clone propagates unborn HEAD from non-empty repo' '
! grep "warning:" stderr
'
+test_expect_success 'defaulted HEAD uses remote branch if available' '
+ test_when_finished "rm -rf file_unborn_parent file_unborn_child" &&
+
+ git init file_unborn_parent &&
+ (
+ cd file_unborn_parent &&
+ git config lsrefs.unborn ignore &&
+ git checkout -b branchwithstuff &&
+ test_commit --no-tag stuff &&
+ git symbolic-ref HEAD refs/heads/mydefaultbranch
+ ) &&
+
+ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
+ git -c init.defaultBranch=branchwithstuff -c protocol.version=2 \
+ clone "file://$(pwd)/file_unborn_parent" \
+ file_unborn_child 2>stderr &&
+ grep "refs/heads/branchwithstuff" file_unborn_child/.git/HEAD &&
+ test_path_is_file file_unborn_child/stuff.t &&
+ ! grep "warning:" stderr
+'
+
test_expect_success 'fetch with file:// using protocol v2' '
test_when_finished "rm -f log" &&