mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-13 22:03:51 -05:00
Return empty string on FugitiveFind() with no Git dir
Previously, we would return a path from the current working directory in this case, which was a good fallback for :Gedit but unhelpful for general programmatic usage.
This commit is contained in:
@@ -914,7 +914,7 @@ function! s:Owner(path, ...) abort
|
|||||||
elseif commit ==# '0'
|
elseif commit ==# '0'
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
let merge_head = s:MergeHead()
|
let merge_head = s:MergeHead(dir)
|
||||||
if empty(merge_head)
|
if empty(merge_head)
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
@@ -1023,10 +1023,10 @@ function! fugitive#Find(object, ...) abort
|
|||||||
endif
|
endif
|
||||||
let dir = a:0 ? a:1 : s:Dir()
|
let dir = a:0 ? a:1 : s:Dir()
|
||||||
if empty(dir)
|
if empty(dir)
|
||||||
let file = matchstr(a:object, '^\%(:\d:\|[^:]*:\)\zs.*', '', '')
|
let file = matchstr(a:object, '^\%(:\d:\|[^:]*:\)\zs\%(\.\.\=$\|\.\.\=/.*\|/.*\|\w:/.*\)')
|
||||||
let dir = FugitiveExtractGitDir(file)
|
let dir = FugitiveExtractGitDir(file)
|
||||||
if empty(dir)
|
if empty(dir)
|
||||||
return fnamemodify(FugitiveVimPath(len(file) ? file : a:object), ':p')
|
return ''
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
let tree = s:Tree(dir)
|
let tree = s:Tree(dir)
|
||||||
@@ -1049,7 +1049,7 @@ function! fugitive#Find(object, ...) abort
|
|||||||
let f = simplify(dir . f)
|
let f = simplify(dir . f)
|
||||||
endif
|
endif
|
||||||
elseif rev ==# ':/'
|
elseif rev ==# ':/'
|
||||||
let f = base
|
let f = tree
|
||||||
elseif rev =~# '^\.\%(/\|$\)'
|
elseif rev =~# '^\.\%(/\|$\)'
|
||||||
let f = base . rev[1:-1]
|
let f = base . rev[1:-1]
|
||||||
elseif rev =~# '^::\%(/\|\a\+\:\)'
|
elseif rev =~# '^::\%(/\|\a\+\:\)'
|
||||||
@@ -1080,6 +1080,8 @@ function! fugitive#Find(object, ...) abort
|
|||||||
let f = matchstr(rev, ')\zs.*')
|
let f = matchstr(rev, ')\zs.*')
|
||||||
if f=~# '^\.\.\=\%(/\|$\)'
|
if f=~# '^\.\.\=\%(/\|$\)'
|
||||||
let f = simplify(getcwd() . '/' . f)
|
let f = simplify(getcwd() . '/' . f)
|
||||||
|
elseif empty(f)
|
||||||
|
let f = base
|
||||||
elseif f !~# '^/\|^\%(\a\a\+:\).*\%(//\|::\)' . (has('win32') ? '\|^\a:/' : '')
|
elseif f !~# '^/\|^\%(\a\a\+:\).*\%(//\|::\)' . (has('win32') ? '\|^\a:/' : '')
|
||||||
let f = base . '/' . f
|
let f = base . '/' . f
|
||||||
endif
|
endif
|
||||||
@@ -1106,7 +1108,7 @@ function! fugitive#Find(object, ...) abort
|
|||||||
call map(commits, 'empty(v:val) || v:val ==# "@" ? "HEAD" : v:val')
|
call map(commits, 'empty(v:val) || v:val ==# "@" ? "HEAD" : v:val')
|
||||||
let commit = matchstr(s:ChompDefault('', [dir, 'merge-base'] + commits + ['--']), '\<[0-9a-f]\{40,\}\>')
|
let commit = matchstr(s:ChompDefault('', [dir, 'merge-base'] + commits + ['--']), '\<[0-9a-f]\{40,\}\>')
|
||||||
endif
|
endif
|
||||||
if commit !~# '^[0-9a-f]\{40,\}$'
|
if commit !~# '^[0-9a-f]\{40,\}$\|^$'
|
||||||
let commit = matchstr(s:ChompDefault('', [dir, 'rev-parse', '--verify', commit . (len(file) ? '^{}' : ''), '--']), '\<[0-9a-f]\{40,\}\>')
|
let commit = matchstr(s:ChompDefault('', [dir, 'rev-parse', '--verify', commit . (len(file) ? '^{}' : ''), '--']), '\<[0-9a-f]\{40,\}\>')
|
||||||
if empty(commit) && len(file)
|
if empty(commit) && len(file)
|
||||||
let commit = repeat('0', 40)
|
let commit = repeat('0', 40)
|
||||||
@@ -1122,8 +1124,16 @@ function! fugitive#Find(object, ...) abort
|
|||||||
return FugitiveVimPath(f)
|
return FugitiveVimPath(f)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:Generate(rev, ...) abort
|
function! s:Generate(object, ...) abort
|
||||||
return fugitive#Find(a:rev, a:0 ? a:1 : s:Dir())
|
let dir = a:0 ? a:1 : s:Dir()
|
||||||
|
let f = fugitive#Find(a:object, dir)
|
||||||
|
if !empty(f)
|
||||||
|
return f
|
||||||
|
elseif a:object ==# ':/'
|
||||||
|
return len(dir) ? FugitiveVimPath('fugitive://' . dir . '//0') : '.'
|
||||||
|
endif
|
||||||
|
let file = matchstr(a:object, '^\%(:\d:\|[^:]*:\)\zs.*')
|
||||||
|
return fnamemodify(FugitiveVimPath(len(file) ? file : a:object), ':p')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:DotRelative(path, ...) abort
|
function! s:DotRelative(path, ...) abort
|
||||||
@@ -4890,7 +4900,7 @@ function! s:OpenParse(string, wants_cmd) abort
|
|||||||
endif
|
endif
|
||||||
let dir = s:Dir()
|
let dir = s:Dir()
|
||||||
let efile = s:Expand(file)
|
let efile = s:Expand(file)
|
||||||
let url = fugitive#Find(efile, dir)
|
let url = s:Generate(efile, dir)
|
||||||
|
|
||||||
if a:wants_cmd && file[0] ==# '>' && efile[0] !=# '>' && get(b:, 'fugitive_type', '') isnot# 'tree' && &filetype !=# 'netrw'
|
if a:wants_cmd && file[0] ==# '>' && efile[0] !=# '>' && get(b:, 'fugitive_type', '') isnot# 'tree' && &filetype !=# 'netrw'
|
||||||
let line = line('.')
|
let line = line('.')
|
||||||
@@ -5133,9 +5143,9 @@ function! fugitive#WriteCommand(line1, line2, range, bang, mods, arg, args) abor
|
|||||||
setlocal nomodified
|
setlocal nomodified
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let one = s:Generate(':1:'.file)
|
let one = fugitive#Find(':1:'.file)
|
||||||
let two = s:Generate(':2:'.file)
|
let two = fugitive#Find(':2:'.file)
|
||||||
let three = s:Generate(':3:'.file)
|
let three = fugitive#Find(':3:'.file)
|
||||||
for nr in range(1,bufnr('$'))
|
for nr in range(1,bufnr('$'))
|
||||||
let name = fnamemodify(bufname(nr), ':p')
|
let name = fnamemodify(bufname(nr), ':p')
|
||||||
if bufloaded(nr) && !getbufvar(nr,'&modified') && (name ==# one || name ==# two || name ==# three)
|
if bufloaded(nr) && !getbufvar(nr,'&modified') && (name ==# one || name ==# two || name ==# three)
|
||||||
@@ -5144,7 +5154,7 @@ function! fugitive#WriteCommand(line1, line2, range, bang, mods, arg, args) abor
|
|||||||
endfor
|
endfor
|
||||||
|
|
||||||
unlet! restorewinnr
|
unlet! restorewinnr
|
||||||
let zero = s:Generate(':0:'.file)
|
let zero = fugitive#Find(':0:'.file)
|
||||||
silent exe s:DoAutocmd('BufWritePost ' . s:fnameescape(zero))
|
silent exe s:DoAutocmd('BufWritePost ' . s:fnameescape(zero))
|
||||||
for tab in range(1,tabpagenr('$'))
|
for tab in range(1,tabpagenr('$'))
|
||||||
for winnr in range(1,tabpagewinnr(tab,'$'))
|
for winnr in range(1,tabpagewinnr(tab,'$'))
|
||||||
@@ -5356,7 +5366,7 @@ function! fugitive#Diffsplit(autodir, keepfocus, mods, arg, args) abort
|
|||||||
exe pre
|
exe pre
|
||||||
let mods = (a:autodir ? s:diff_modifier(len(parents) + 1) : '') . s:Mods(mods, 'leftabove')
|
let mods = (a:autodir ? s:diff_modifier(len(parents) + 1) : '') . s:Mods(mods, 'leftabove')
|
||||||
let nr = bufnr('')
|
let nr = bufnr('')
|
||||||
execute mods 'split' s:fnameescape(s:Generate(parents[0]))
|
execute mods 'split' s:fnameescape(fugitive#Find(parents[0]))
|
||||||
call s:Map('n', 'dp', ':diffput '.nr.'<Bar>diffupdate<CR>', '<silent>')
|
call s:Map('n', 'dp', ':diffput '.nr.'<Bar>diffupdate<CR>', '<silent>')
|
||||||
let nr2 = bufnr('')
|
let nr2 = bufnr('')
|
||||||
call s:diffthis()
|
call s:diffthis()
|
||||||
@@ -5364,7 +5374,7 @@ function! fugitive#Diffsplit(autodir, keepfocus, mods, arg, args) abort
|
|||||||
call s:Map('n', 'd2o', ':diffget '.nr2.'<Bar>diffupdate<CR>', '<silent>')
|
call s:Map('n', 'd2o', ':diffget '.nr2.'<Bar>diffupdate<CR>', '<silent>')
|
||||||
let mods = substitute(mods, '\Cleftabove\|rightbelow\|aboveleft\|belowright', '\=submatch(0) =~# "f" ? "rightbelow" : "leftabove"', '')
|
let mods = substitute(mods, '\Cleftabove\|rightbelow\|aboveleft\|belowright', '\=submatch(0) =~# "f" ? "rightbelow" : "leftabove"', '')
|
||||||
for i in range(len(parents)-1, 1, -1)
|
for i in range(len(parents)-1, 1, -1)
|
||||||
execute mods 'split' s:fnameescape(s:Generate(parents[i]))
|
execute mods 'split' s:fnameescape(fugitive#Find(parents[i]))
|
||||||
call s:Map('n', 'dp', ':diffput '.nr.'<Bar>diffupdate<CR>', '<silent>')
|
call s:Map('n', 'dp', ':diffput '.nr.'<Bar>diffupdate<CR>', '<silent>')
|
||||||
let nrx = bufnr('')
|
let nrx = bufnr('')
|
||||||
call s:diffthis()
|
call s:diffthis()
|
||||||
@@ -6561,7 +6571,7 @@ function! s:StatusCfile(...) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#StatusCfile() abort
|
function! fugitive#StatusCfile() abort
|
||||||
let file = s:Generate(s:StatusCfile()[0])
|
let file = fugitive#Find(s:StatusCfile()[0])
|
||||||
return empty(file) ? fugitive#Cfile() : s:fnameescape(file)
|
return empty(file) ? fugitive#Cfile() : s:fnameescape(file)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -6591,7 +6601,7 @@ function! s:MessageCfile(...) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#MessageCfile() abort
|
function! fugitive#MessageCfile() abort
|
||||||
let file = s:Generate(s:MessageCfile())
|
let file = fugitive#Find(s:MessageCfile())
|
||||||
return empty(file) ? fugitive#Cfile() : s:fnameescape(file)
|
return empty(file) ? fugitive#Cfile() : s:fnameescape(file)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user