Skip to content

Commit

Permalink
bash prompt: print unique detached HEAD abbreviated object name
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
SZEDER Gábor committed Jun 24, 2013
1 parent 868dc1a commit e8f21ca
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion contrib/completion/git-prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ __git_ps1 ()
git describe --tags --exact-match HEAD ;;
esac 2>/dev/null)" ||

b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
b="$(git rev-parse --short HEAD 2>/dev/null)..." ||
b="unknown"
b="($b)"
}
Expand Down
3 changes: 2 additions & 1 deletion t/t9903-bash-prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ test_expect_success SYMLINKS 'prompt - branch name - symlink symref' '
'

test_expect_success 'prompt - detached head' '
printf " ((%s...))" $(git log -1 --format="%h" b1^) >expected &&
printf " ((%s...))" $(git log -1 --format="%h" --abbrev=13 b1^) >expected &&
test_config core.abbrev 13 &&
git checkout b1^ &&
test_when_finished "git checkout master" &&
__git_ps1 >"$actual" &&
Expand Down

0 comments on commit e8f21ca

Please sign in to comment.