mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-12 21:33:53 -05:00
Improve robustness of status --porcelain=v2 parsing
Closes https://github.com/tpope/vim-fugitive/issues/1388
This commit is contained in:
@@ -1628,21 +1628,14 @@ function! fugitive#BufReadStatus() abort
|
|||||||
throw 'fugitive: ' . message
|
throw 'fugitive: ' . message
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let i = match(output, '^[^#]')
|
let props = {}
|
||||||
let head = matchlist(output[:i], '^# branch\.head \zs.*$')[0]
|
let i = 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
|
|
||||||
|
|
||||||
while i < len(output)
|
while i < len(output)
|
||||||
let line = output[i]
|
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]})
|
call add(untracked, {'type': 'File', 'status': line[0], 'filename': line[2:-1]})
|
||||||
elseif line[0] !=# '#'
|
elseif line[0] !=# '#'
|
||||||
if line[0] ==# 'u'
|
if line[0] ==# 'u'
|
||||||
@@ -1664,6 +1657,15 @@ function! fugitive#BufReadStatus() abort
|
|||||||
endif
|
endif
|
||||||
let i += 1
|
let i += 1
|
||||||
endwhile
|
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
|
else " git < 2.11
|
||||||
let cmd += ['status', '--porcelain', '-bz']
|
let cmd += ['status', '--porcelain', '-bz']
|
||||||
let [output, message, exec_error] = s:NullError(cmd)
|
let [output, message, exec_error] = s:NullError(cmd)
|
||||||
|
|||||||
Reference in New Issue
Block a user