git: Add support for detached head state
This commit is contained in:
parent
3d711323d5
commit
e8649fc440
@ -660,6 +660,10 @@ _lp_git_branch()
|
||||
local gitdir="$(git rev-parse --git-dir 2>/dev/null)"
|
||||
[[ $? -ne 0 || "${gitdir##*/}" != .git ]] && return
|
||||
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
|
||||
echo "${branch#refs/heads/}"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user