Skip to content

Commit

Permalink
completion: simplify "current branch" in __git_ps1()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed May 17, 2009
1 parent 8763dbb commit ff790b6
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions contrib/completion/git-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ff790b6

Please sign in to comment.