From 009f7932fb8da73dad1f74a61cfabc85df6fd8bb Mon Sep 17 00:00:00 2001 From: Cimbali Date: Wed, 22 Nov 2017 18:54:29 +0100 Subject: [PATCH] Show #branch#head() as "ref-or-sha1(current-branch)" Only changes anything in the case of using fugitive to show a file that is not from the current working directory. --- autoload/airline/extensions/branch.vim | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/autoload/airline/extensions/branch.vim b/autoload/airline/extensions/branch.vim index f2798bcb..7e9625bd 100644 --- a/autoload/airline/extensions/branch.vim +++ b/autoload/airline/extensions/branch.vim @@ -81,7 +81,9 @@ else endfunction endif -let s:git_dirs = {} + +" Fugitive special revisions. call '0' "staging" ? +let s:names = {'0': 'index', '1': 'ancestor', '2':'target', '3':'merged'} function! s:update_git_branch() if !s:has_fugitive @@ -91,6 +93,22 @@ function! s:update_git_branch() let name = fugitive#head(7) + try + let commit = fugitive#buffer().commit() + + if has_key(s:names, commit) + let name = get(s:names, commit)."(".name.")" + elseif !empty(commit) + let ref = fugitive#repo().git_chomp('describe', '--all', '--exact-match', commit) + if ref !~ "^fatal: no tag exactly matches" + let name = s:format_name(substitute(ref, '\v\C^%(heads/|remotes/|tags/)=','',''))."(".name.")" + else + let name = commit[:6]."(".name.")" + endif + endif + catch + endtry + let s:vcs_config['git'].branch = name endfunction