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

View File

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

View File

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