From 83a7e30790fafa475733909babe351b3ea6f2459 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Wed, 20 Aug 2014 18:52:15 -0400 Subject: [PATCH] use commit hash as git branch with detached HEAD Abbreviated to 7 characters to match `git rev-parse --short HEAD`. --- autoload/airline/extensions/branch.vim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/autoload/airline/extensions/branch.vim b/autoload/airline/extensions/branch.vim index 954b0f6..250184d 100644 --- a/autoload/airline/extensions/branch.vim +++ b/autoload/airline/extensions/branch.vim @@ -21,7 +21,12 @@ function! s:get_git_branch(path) else try let line = join(readfile(dir . '/HEAD')) - let name = strpart(line, 16) + if strpart(line, 0, 16) == 'ref: refs/heads/' + let name = strpart(line, 16) + else + " raw commit hash + let name = strpart(line, 0, 7) + endif catch let name = '' endtry @@ -39,7 +44,7 @@ function! airline#extensions#branch#head() let b:airline_head = '' if s:has_fugitive && !exists('b:mercurial_dir') - let b:airline_head = fugitive#head() + let b:airline_head = fugitive#head(7) if empty(b:airline_head) && !exists('b:git_dir') let b:airline_head = s:get_git_branch(expand("%:p:h"))