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:
authorChris Webb <chris@arachsys.com>2012-06-26 19:06:42 +0400
committerJunio C Hamano <gitster@pobox.com>2012-06-26 22:11:14 +0400
commit8ced1aa08f9e1798b2b3fec41a0598ef79b477fe (patch)
tree4cad32f246e34e8686b0dae6045c60875de8f4ae /t/t2017-checkout-orphan.sh
parentabe199808c6586047fb7255b80e3d17ffc26bf6c (diff)
git-checkout: disallow --detach on unborn branch
abe199808c (git checkout -b: allow switching out of an unborn branch) introduced a bug demonstrated by git checkout --orphan foo git checkout --detach git symbolic-ref HEAD which gives 'refs/heads/(null)'. This happens because we strbuf_addf(&branch_ref, "refs/heads/%s", opts->new_branch) when opts->new_branch can be NULL for --detach. Catch and forbid this case, adding a test to t2017 to catch it in future. Signed-off-by: Chris Webb <chris@arachsys.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t2017-checkout-orphan.sh')
-rwxr-xr-xt/t2017-checkout-orphan.sh6
1 files changed, 6 insertions, 0 deletions
diff --git a/t/t2017-checkout-orphan.sh b/t/t2017-checkout-orphan.sh
index 0e3b8582f2..655f278c5f 100755
--- a/t/t2017-checkout-orphan.sh
+++ b/t/t2017-checkout-orphan.sh
@@ -116,4 +116,10 @@ test_expect_success '--orphan refuses to switch if a merge is needed' '
git reset --hard
'
+test_expect_success 'cannot --detach on an unborn branch' '
+ git checkout master &&
+ git checkout --orphan new &&
+ test_must_fail git checkout --detach
+'
+
test_done