From e8c5b604db4504f95cb6e1eb141edad300583ee1 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sat, 26 Oct 2019 08:49:23 -0400 Subject: [PATCH] Improve robustness of status --porcelain=v2 parsing Closes https://github.com/tpope/vim-fugitive/issues/1388 --- autoload/fugitive.vim | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 53bd6ca..2927401 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -1628,21 +1628,14 @@ function! fugitive#BufReadStatus() abort throw 'fugitive: ' . message endif - let i = match(output, '^[^#]') - let head = matchlist(output[:i], '^# branch\.head \zs.*$')[0] - let pull = get(matchlist(output[:i], '^# branch\.upstream \zs.*$'), 0, '') - if len(pull) - let branch = head - elseif head ==# '(detached)' - let head = matchlist(output[:i], '^# branch\.oid \zs.*$')[0][:10] - let branch = '' - else - let branch = head - endif - + let props = {} + let i = 0 while i < len(output) let line = output[i] - if line[0] ==# '?' + let prop = matchlist(line, '# \(\S\+\) \(.*\)') + if len(prop) + let props[prop[1]] = prop[2] + elseif line[0] ==# '?' call add(untracked, {'type': 'File', 'status': line[0], 'filename': line[2:-1]}) elseif line[0] !=# '#' if line[0] ==# 'u' @@ -1664,6 +1657,15 @@ function! fugitive#BufReadStatus() abort endif let i += 1 endwhile + let branch = substitute(get(props, 'branch.head', '(unknown)'), '\C^(\%(detached\|unknown\))$', '', '') + if len(branch) + let head = branch + elseif has_key(props, 'branch.oid') + let head = props['branch.oid'][0:10] + else + let head = FugitiveHead(11) + endif + let pull = get(props, 'branch.upstream', '') else " git < 2.11 let cmd += ['status', '--porcelain', '-bz'] let [output, message, exec_error] = s:NullError(cmd)