bash prompt: print unique detached HEAD abbreviated object name

When describing a detached HEAD according to the $GIT_PS1_DESCRIBE environment variable fails, __git_ps1() runs 'cut -c1-7 .git/HEAD' to show the 7 hexdigits abbreviated commit object name in the prompt. Obviously, this neither respects core.abbrev nor produces a unique object name. Fix this by using 'git rev-parse --short HEAD' instead and adjust the corresponding test to use non-standard number of hexdigits. Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>

SZEDER Gábor committed Jun 24, 2013 at 01:55 UTC e8f21caf94287d838cfffe8301b28fdc45480ac8
2 files changed +3 -2
contrib/completion/git-prompt.sh
+1 -1
@@ -392,7 +392,7 @@ __git_ps1 ()
392 git describe --tags --exact-match HEAD ;;
393 esac 2>/dev/null)" ||
394
395 - b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
395 + b="$(git rev-parse --short HEAD 2>/dev/null)..." ||
396 b="unknown"
397 b="($b)"
398 }
t/t9903-bash-prompt.sh
+2 -1
@@ -50,7 +50,8 @@ test_expect_success SYMLINKS 'prompt - branch name - symlink symref' '
50 '
51
52 test_expect_success 'prompt - detached head' '
53 - printf " ((%s...))" $(git log -1 --format="%h" b1^) >expected &&
53 + printf " ((%s...))" $(git log -1 --format="%h" --abbrev=13 b1^) >expected &&
54 + test_config core.abbrev 13 &&
55 git checkout b1^ &&
56 test_when_finished "git checkout master" &&
57 __git_ps1 >"$actual" &&