git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Shawn O. Pearce" <spearce@spearce.org>
Cc: git@vger.kernel.org
Subject: [PATCH 1/2] completion: simplify "current branch" in __git_ps1()
Date: Sun, 10 May 2009 01:53:19 -0700	[thread overview]
Message-ID: <7v1vqx2vb4.fsf@alter.siamese.dyndns.org> (raw)

As I very often work on a detached HEAD, I found it pretty confusing
when __git_ps1() said 'some-name'.  Did I create a branch with that name
by mistake, or do I happen to be on a commit with that exact tag?

This patch fixes the issue by enclosing non branch names in a pair of
parentheses when used to substitute %s token in __git_ps1() argument.

It also fixes a small bug where the branch part is left empty when
.git/HEAD is unreadable for whatever reason.  The output now says
"(unknown)".

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 contrib/completion/git-completion.bash |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 1683e6d..ccc7e0d 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -106,13 +106,14 @@ __git_ps1 ()
 			if [ -f "$g/BISECT_LOG" ]; then
 				r="|BISECTING"
 			fi
-			if ! b="$(git symbolic-ref HEAD 2>/dev/null)"; then
-				if ! b="$(git describe --exact-match HEAD 2>/dev/null)"; then
-					if [ -r "$g/HEAD" ]; then
-						b="$(cut -c1-7 "$g/HEAD")..."
-					fi
-				fi
-			fi
+
+			b="$(git symbolic-ref HEAD 2>/dev/null)" || {
+				b="$(git describe --exact-match HEAD 2>/dev/null)" ||
+				b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
+				b="unknown"
+
+				b="($b)"
+			}
 		fi
 
 		local w
-- 
1.6.3.9.g6345d

                 reply	other threads:[~2009-05-10  8:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

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

  git send-email \
    --in-reply-to=7v1vqx2vb4.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=spearce@spearce.org \
    /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.
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 NNTP newsgroup(s).