git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git checkout: create unparented branch by --orphan

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 20, 2010, 20:54 UTC
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 <start_point>' '
 '
 
 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
Previous: Erick MattosNext: Erick Mattos
Message 6 of 7 in “git checkout: create unparented branch by --orphan”
  1. git checkout: create unparented branch by --orphanErick Mattos, Mar 18, 2010
  2. Junio C HamanoMar 20, 2010
  3. Erick MattosMar 20, 2010
  4. Junio C HamanoMar 20, 2010
  5. Erick MattosMar 20, 2010
  6. Junio C HamanoMar 20, 2010
  7. Erick MattosMar 20, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.