Error when core.worktree expected but missing

This commit is contained in:
Tim Pope
2021-07-03 03:42:14 -04:00
parent f920245d6b
commit 957d962e06
3 changed files with 27 additions and 8 deletions

View File

@@ -88,11 +88,16 @@ function! s:VersionCheck() abort
endif
endfunction
let s:worktree_error = "core.worktree is required when using an external Git dir"
function! s:DirCheck(...) abort
let vcheck = s:VersionCheck()
if !empty(vcheck)
return vcheck
elseif !empty(a:0 ? s:Dir(a:1) : s:Dir())
endif
let dir = a:0 ? s:Dir(a:1) : s:Dir()
if !empty(dir) && FugitiveWorkTree(dir, 1) is# 0
return 'return ' . string('echoerr "fugitive: ' . s:worktree_error . '"')
elseif !empty(dir)
return ''
elseif empty(bufname(''))
return 'return ' . string('echoerr "fugitive: working directory does not belong to a Git repository"')
@@ -2134,8 +2139,10 @@ function! fugitive#BufReadStatus() abort
if push !=# pull
call s:AddHeader('Push', push)
endif
if empty(s:Tree())
if get(fugitive#ConfigGetAll('core.bare', config), 0, 'true') !~# '^\%(false\|no|off\|0\|\)$'
call s:AddHeader('Bare', 'yes')
elseif empty(s:Tree())
call s:AddHeader('Error', s:worktree_error)
endif
if get(fugitive#ConfigGetAll('advice.statusHints', config), 0, 'true') !~# '^\%(false\|no|off\|0\|\)$'
call s:AddHeader('Help', 'g?')
@@ -2867,6 +2874,9 @@ unlet s:colortype
function! fugitive#Command(line1, line2, range, bang, mods, arg) abort
exe s:VersionCheck()
let dir = s:Dir()
if len(dir)
exe s:DirCheck(dir)
endif
let config = copy(fugitive#Config(dir))
let [args, after] = s:SplitExpandChain(a:arg, s:Tree(dir))
let flags = []

View File

@@ -180,7 +180,12 @@ function! FugitiveCommonDir(...) abort
endfunction
function! FugitiveWorkTree(...) abort
return s:Tree(FugitiveGitDir(a:0 ? a:1 : -1))
let tree = s:Tree(FugitiveGitDir(a:0 ? a:1 : -1))
if tree isnot# 0 || a:0 > 1
return tree
else
return ''
endif
endfunction
function! FugitiveIsGitDir(path) abort
@@ -204,9 +209,14 @@ function! s:Tree(path) abort
let config_file = dir . '/config'
if filereadable(config_file)
let config = readfile(config_file,'',10)
call filter(config,'v:val =~# "^\\s*worktree *="')
if len(config) == 1
let wt_config = filter(copy(config),'v:val =~# "^\\s*worktree *="')
if len(wt_config) == 1
let worktree = FugitiveVimPath(matchstr(config[0], '= *\zs.*'))
else
call filter(config,'v:val =~# "^\\s*bare *= *false *$"')
if len(config)
let s:worktree_for_dir[dir] = 0
endif
endif
elseif filereadable(dir . '/gitdir')
let worktree = fnamemodify(FugitiveVimPath(readfile(dir . '/gitdir')[0]), ':h')
@@ -358,7 +368,7 @@ function! s:ProjectionistDetect() abort
if empty(base)
let base = s:Tree(dir)
endif
if len(base)
if !empty(base)
if exists('+shellslash') && !&shellslash
let base = tr(base, '/', '\')
endif

View File

@@ -8,7 +8,7 @@ syn spell notoplevel
syn include @fugitiveDiff syntax/diff.vim
syn match fugitiveHeader /^[A-Z][a-z][^:]*:/ nextgroup=fugitiveHash,fugitiveSymbolicRef skipwhite
syn match fugitiveBareHeader /^Bare:/
syn match fugitiveHeader /^Bare:\|^Warning:\|^Error:/
syn match fugitiveHelpHeader /^Help:/ nextgroup=fugitiveHelpTag skipwhite
syn match fugitiveHelpTag /\S\+/ contained
@@ -36,7 +36,6 @@ for s:section in ['Untracked', 'Unstaged', 'Staged']
endfor
unlet s:section
hi def link fugitiveBareHeader fugitiveHeader
hi def link fugitiveHelpHeader fugitiveHeader
hi def link fugitiveHeader Label
hi def link fugitiveHelpTag Tag