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

Re: [1.8.0] git checkout refs/heads/foo checks out branch foo

From
Jeff King <peff@peff.net>
Date
Feb 7, 2011, 23:45 UTC
Message-ID
<20110207234526.GA28336@sigill.intra.peff.net>
In-Reply-To
<7vaai7s9g4.fsf@alter.siamese.dyndns.org>
On Mon, Feb 07, 2011 at 03:37:15PM -0800, Junio C Hamano wrote:
Show 9 quoted lines
> > Subject: commit: document --detach synonym for "git checkout foo^{commit}"
> >
> > For example, one might use this when making a temporary merge to test
> > that two topics work well together.
> >
> > This patch just documents the option.  It is not meant for application
> > without an implementation and tests for the option.
> 
> On top of v1.7.3.5-1-g0cb6ad3 (uk/checkout-ambiguous-ref)...

Well, I started on tests and your email came just as I was about to actually implement. So here are the tests. We didn't seem to have any explicit checkout-detached tests before, so I tried to cover existing methods in addition to the new option (which means Martin will need to tweak one of the tests below when implementing his proposal).

Jonathan, do you want to roll all of these up into a single patch?
---
 t/t2020-checkout-detach.sh |   62 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 62 insertions(+), 0 deletions(-)
 create mode 100755 t/t2020-checkout-detach.sh
diff --git a/t/t2020-checkout-detach.sh b/t/t2020-checkout-detach.sh
new file mode 100755
index 0000000..886e186
--- /dev/null
+++ b/t/t2020-checkout-detach.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+test_description='checkout into detached HEAD state'
+. ./test-lib.sh
+
+check_detached() {
+	! git symbolic-ref -q HEAD >/dev/null
+}
+
+check_not_detached() {
+	! check_detached
+}
+
+reset() {
+	git checkout master &&
+	check_not_detached
+}
+
+test_expect_success 'setup' '
+	test_commit one &&
+	test_commit two &&
+	git branch branch &&
+	git tag tag
+'
+
+test_expect_success 'checkout branch does not detach' '
+	reset &&
+	git checkout branch &&
+	check_not_detached
+'
+
+test_expect_success 'checkout tag detaches' '
+	reset &&
+	git checkout tag &&
+	check_detached
+'
+
+test_expect_success 'checkout branch by full name detaches' '
+	reset &&
+	git checkout refs/heads/branch &&
+	check_detached
+'
+
+test_expect_success 'checkout non-ref detaches' '
+	reset &&
+	git checkout branch^ &&
+	check_detached
+'
+
+test_expect_success 'checkout ref^0 detaches' '
+	reset &&
+	git checkout branch^0 &&
+	check_detached
+'
+
+test_expect_success 'checkout --detach detaches' '
+	reset &&
+	git checkout --detach branch &&
+	check_detached
+'
+
+test_done
-- 
1.7.4.rc2.27.gd0787
Previous: Junio C HamanoNext: Jonathan Nieder
Message 7 of 18 in “[1.8.0] git checkout refs/heads/foo checks out branch foo”
  1. Martin von ZweigbergkFeb 7, 2011
  2. Junio C HamanoFeb 7, 2011
  3. Jeff KingFeb 7, 2011
  4. Sverre RabbelierFeb 7, 2011
  5. Jonathan NiederFeb 7, 2011
  6. Junio C HamanoFeb 7, 2011
  7. Jeff KingFeb 7, 2011
  8. Jonathan NiederFeb 8, 2011
  9. Jeff KingFeb 8, 2011
  10. Martin von ZweigbergkFeb 8, 2011
  11. checkout: introduce --detach synonym for "git checkout foo^{commit}"Jonathan Nieder, Feb 8, 2011
  12. Jonathan NiederFeb 8, 2011
  13. 0/3 checkout: introduce --detach synonym for "git checkout foo^{commit}"Jonathan Nieder, Feb 8, 2011
  14. 1/3 checkout: split off a function to peel away branchname argJonathan Nieder, Feb 8, 2011
  15. 2/3 checkout: introduce --detach synonym for "git checkout foo^{commit}"Jonathan Nieder, Feb 8, 2011
  16. 3/3 checkout: rearrange update_refs_for_switch for clarityJonathan Nieder, Feb 8, 2011
  17. Heiko VoigtFeb 7, 2011
  18. Martin von ZweigbergkFeb 8, 2011

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.