From e8649fc440d9c86a05c213d56505d4e4fb65a3fc Mon Sep 17 00:00:00 2001 From: Jonas Bengtsson Date: Tue, 12 Mar 2013 20:47:52 +0100 Subject: [PATCH] git: Add support for detached head state --- liquidprompt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/liquidprompt b/liquidprompt index 0785fc5..c5d87f2 100755 --- a/liquidprompt +++ b/liquidprompt @@ -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/}" }