From: Junio C Hamano Date: Sat, 20 Mar 2010 20:54:30 GMT Subject: Re: [PATCH] git checkout: create unparented branch by --orphan Message-ID: <7vfx3ubto9.fsf@alter.siamese.dyndns.org> In-Reply-To: <55bacdd31003201336u685f4b91u5206ca719609d153@mail.gmail.com> I hope I am not giving you undue burden, but here is what I would add. One thing that I am not sure about is what to do with "-l --orhpan". --- t/t2017-checkout-orphan.sh | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 42 insertions(+), 1 deletions(-) diff --git a/t/t2017-checkout-orphan.sh b/t/t2017-checkout-orphan.sh index 5a9a3fa..e80e167 100755 --- a/t/t2017-checkout-orphan.sh +++ b/t/t2017-checkout-orphan.sh @@ -44,7 +44,48 @@ test_expect_success '--orphan creates a new orphan branch from ' ' ' test_expect_success '--orphan must be rejected with -b' ' - test_must_fail git checkout --orphan new -b newer + git checkout master && + test_must_fail git checkout --orphan new -b newer && + test refs/heads/master = "$(git symbolic-ref HEAD)" +' + +test_expect_success '--orphan is rejected with an existing name' ' + git checkout master && + test_must_fail git checkout --orphan master && + test refs/heads/master = "$(git symbolic-ref HEAD)" +' + +test_expect_success '--orhapn refuses to switch if a merge is needed' ' + git checkout master && + git reset --hard && + echo local >>"$TEST_FILE" && + cat "$TEST_FILE" >"$TEST_FILE.saved" && + test_must_fail git checkout --orphan gamma master^ && + test refs/heads/master = "$(git symbolic-ref HEAD)" && + test_cmp "$TEST_FILE" "$TEST_FILE.saved" && + git diff-index --quiet --cached HEAD && + git reset --hard +' + +test_expect_success '--orphan does not mix well with -t' ' + git checkout master && + test_must_fail git checkout -t master --orphan gamma && + test refs/heads/master = "$(git symbolic-ref HEAD)" +' + +test_expect_success '--orphan ignores branch.autosetupmerge' ' + git checkout -f master && + git config branch.autosetupmerge always && + git checkout --orphan delta && + test -z "$(git config branch.delta.merge)" && + test refs/heads/delta = "$(git symbolic-ref HEAD)" && + test_must_fail git rev-parse --verify HEAD^ +' + +# This is iffy. +test_expect_success '--orphan does not mix well with -l' ' + git checkout -f master && + test_must_fail git checkout -l --orphan gamma ' test_done