completion: simplify "current branch" in __git_ps1()
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>
Junio C Hamano committed
May 10, 2009 at 01:53 UTC
ff790b6a4bb7fa3bbccd5ea23cefd89da900aa2e
1 file changed
+8
-7
contrib/completion/git-completion.bash
+8
-7
@@ -106,13 +106,14 @@ __git_ps1 ()
106
if [ -f "$g/BISECT_LOG" ]; then
107
r="|BISECTING"
108
fi
109
- if ! b="$(git symbolic-ref HEAD 2>/dev/null)"; then
110
- if ! b="$(git describe --exact-match HEAD 2>/dev/null)"; then
111
- if [ -r "$g/HEAD" ]; then
112
- b="$(cut -c1-7 "$g/HEAD")..."
113
- fi
114
- fi
115
- fi
109
+
110
+ b="$(git symbolic-ref HEAD 2>/dev/null)" || {
111
+ b="$(git describe --exact-match HEAD 2>/dev/null)" ||
112
+ b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
113
+ b="unknown"
114
+
115
+ b="($b)"
116
+ }
117
fi
118
119
local w