git: Add support for detached head state

This commit is contained in:
Jonas Bengtsson 2013-03-12 20:47:52 +01:00
parent 3d711323d5
commit e8649fc440

View File

@ -660,6 +660,10 @@ _lp_git_branch()
local gitdir="$(git rev-parse --git-dir 2>/dev/null)" local gitdir="$(git rev-parse --git-dir 2>/dev/null)"
[[ $? -ne 0 || "${gitdir##*/}" != .git ]] && return [[ $? -ne 0 || "${gitdir##*/}" != .git ]] && return
local branch="$(git symbolic-ref HEAD 2>/dev/null)" local branch="$(git symbolic-ref HEAD 2>/dev/null)"
if [[ $? -ne 0 || -z "$branch" ]] ; then
# In detached head state, use commit instead
branch="$(git rev-parse --short HEAD 2>/dev/null)"
fi
[[ $? -ne 0 || -z "$branch" ]] && return [[ $? -ne 0 || -z "$branch" ]] && return
echo "${branch#refs/heads/}" echo "${branch#refs/heads/}"
} }