git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Matthias Lederhofer <matled@gmx.net>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: [PATCH] git-checkout: disable guides how to switch branches with ui.guide
Date: Thu, 1 Feb 2007 19:44:03 +0100	[thread overview]
Message-ID: <20070201184403.GA6326@moooo.ath.cx> (raw)
In-Reply-To: <7vlkjip7mu.fsf_-_@assigned-by-dhcp.cox.net>

---
Junio C Hamano <junkio@cox.net> wrote:
> * Detaching head would say which commit I am at and reminds me that
>   I am not on any branch (not that I would detach my HEAD while keeping
>   precious local changes around in any real-world workflow -- this is
>   just a sample session).
> 
>     [git.git (master)]$ git checkout master^
>     M       git-checkout.sh
>     Note: you are not on any branch and are at commit "master^"
>     If you want to create a new branch from this checkout, you may do so
>     (now or later) by using -b with the checkout command again. Example:
>       git checkout -b <new_branch_name>
> 
> * Coming back to an attached state can lose the detached HEAD, so
>   I get warned and stopped.
> 
>     [git.git]$ git checkout master
>     You are not on any branch and switching to branch 'master'
>     may lose your changes.  At this point, you can do one of two things:
>      (1) Decide it is Ok and say 'git checkout -f master';
>      (2) Start a new branch from the current commit, by saying
>          'git checkout -b <branch-name>'.
>     Leaving your HEAD detached; not switching to branch 'master'.
I think these two are too long, after a few times one knows exactly
what to do and all this text is not necessary anymore.

Perhaps the name (ui.guide) should be different, I just did not find
any category to put this in.  The variable could become a general
variable to enable/disable very verbose explanations what to do in a
situation.
---
 git-checkout.sh |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/git-checkout.sh b/git-checkout.sh
index deb4795..1eb8b06 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -5,6 +5,8 @@ SUBDIRECTORY_OK=Sometimes
 . git-sh-setup
 require_work_tree
 
+guide=$(git repo-config --bool --get ui.guide)
+[ -z "$guide" ] && guide=true
 old_name=HEAD
 old=$(git-rev-parse --verify $old_name 2>/dev/null)
 oldbranch=$(git-symbolic-ref $old_name 2>/dev/null)
@@ -155,10 +157,13 @@ then
 	detached="$new"
 	if test -n "$oldbranch"
 	then
-		detach_warn="Note: you are not on any branch and are at commit \"$new_name\"
+		detach_warn="Note: you are not on any branch and are at commit \"$new_name\""
+		if test "$guide" = true; then
+			detach_warn="$detach_warn
 If you want to create a new branch from this checkout, you may do so
 (now or later) by using -b with the checkout command again. Example:
   git checkout -b <new_branch_name>"
+		fi
 	fi
 elif test -z "$oldbranch" && test -n "$branch"
 then
@@ -166,13 +171,18 @@ then
 	if test -z "$force"
 	then
 		git show-ref -d -s | grep "$old" >/dev/null || {
-			echo >&2 \
+			if test "$guide" = true; then
+				echo >&2 \
 "You are not on any branch and switching to branch '$new_name'
 may lose your changes.  At this point, you can do one of two things:
  (1) Decide it is Ok and say 'git checkout -f $new_name';
  (2) Start a new branch from the current commit, by saying
      'git checkout -b <branch-name>'.
 Leaving your HEAD detached; not switching to branch '$new_name'."
+			else
+				echo >&2 \
+"HEAD detached; use -f to switch to branch '$new_name'."
+			fi
 			exit 1;
 		}
 	fi
-- 
1.5.0.rc3.g4a88

  parent reply	other threads:[~2007-02-01 18:44 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-31 19:10 [PATCH] tone down the detached head warning Nicolas Pitre
2007-01-31 23:19 ` Jeff King
2007-01-31 23:25   ` Jakub Narebski
2007-01-31 23:27     ` Jeff King
2007-01-31 23:33       ` Jakub Narebski
2007-01-31 23:54   ` Carl Worth
2007-02-01  0:14     ` Jakub Narebski
2007-02-01  8:44       ` Andy Parkins
2007-02-01 12:48         ` Matthias Lederhofer
2007-02-01  0:11   ` Nicolas Pitre
2007-02-01  3:00     ` Jeff King
2007-02-01  3:23       ` Junio C Hamano
2007-02-01  3:29         ` Jeff King
2007-02-01  3:47           ` Nicolas Pitre
2007-02-01  3:54             ` Jeff King
2007-02-01  9:08         ` [PATCH] detached HEAD -- finishing touches Junio C Hamano
2007-02-01  9:46           ` Raimund Bauer
2007-02-01  9:53           ` Alex Riesen
2007-02-01  9:54             ` Alex Riesen
2007-02-01 18:44           ` Matthias Lederhofer [this message]
2007-02-01 20:42             ` [PATCH] git-checkout: disable guides how to switch branches with ui.guide Junio C Hamano
2007-02-01 20:51               ` Matthias Lederhofer
2007-02-01 21:06                 ` Junio C Hamano
2007-02-01 21:23                   ` Matthias Lederhofer
2007-02-01 21:34                   ` Carl Worth
2007-02-01 21:59                     ` Nicolas Pitre
2007-02-01 22:16                       ` Carl Worth
2007-02-01 23:18                         ` Jakub Narebski
2007-02-01 21:52           ` [PATCH] detached HEAD -- finishing touches Theodore Tso
2007-02-02  1:11             ` Junio C Hamano
2007-02-02  1:16               ` Theodore Tso
2007-02-02  1:27               ` Carl Worth
2007-02-02  1:30                 ` Junio C Hamano
2007-02-02  1:46                   ` Carl Worth
2007-02-02  2:38                     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070201184403.GA6326@moooo.ath.cx \
    --to=matled@gmx.net \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).