mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-15 23:03:51 -05:00
Retool $GIT_INDEX_FILE handling
* Don't attempt to handle relative paths, as there's no guarantee the current working directory is the one Vim was started with. In practice, the only relative path I've seen is `.git/index`, which is already the default and thus harmless to ignore. * Cache the result of FugitiveVimPath(), to allow for slow implementations.
This commit is contained in:
@@ -578,11 +578,19 @@ function! s:PreparePathArgs(cmd, dir, literal, explicit) abort
|
|||||||
return a:cmd
|
return a:cmd
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
let s:git_index_file_env = {}
|
||||||
|
function! s:GitIndexFileEnv() abort
|
||||||
|
if $GIT_INDEX_FILE =~# '^/\|^\a:' && !has_key(s:git_index_file_env, $GIT_INDEX_FILE)
|
||||||
|
let s:git_index_file_env[$GIT_INDEX_FILE] = s:Slash(FugitiveVimPath($GIT_INDEX_FILE))
|
||||||
|
endif
|
||||||
|
return get(s:git_index_file_env, $GIT_INDEX_FILE, '')
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:PrepareEnv(env, dir) abort
|
function! s:PrepareEnv(env, dir) abort
|
||||||
if len($GIT_INDEX_FILE) && len(s:Tree(a:dir)) && !has_key(a:env, 'GIT_INDEX_FILE')
|
if len($GIT_INDEX_FILE) && len(s:Tree(a:dir)) && !has_key(a:env, 'GIT_INDEX_FILE')
|
||||||
let index_dir = substitute($GIT_INDEX_FILE, '[^/]\+$', '', '')
|
let index_dir = substitute(s:GitIndexFileEnv(), '[^/]\+$', '', '')
|
||||||
let our_dir = fugitive#Find('.git/', a:dir)
|
let our_dir = fugitive#Find('.git/', a:dir)
|
||||||
if !s:cpath(index_dir, our_dir) && !s:cpath(resolve(FugitiveVimPath(index_dir)), our_dir)
|
if !s:cpath(index_dir, our_dir) && !s:cpath(resolve(index_dir), our_dir)
|
||||||
let a:env['GIT_INDEX_FILE'] = FugitiveGitPath(fugitive#Find('.git/index', a:dir))
|
let a:env['GIT_INDEX_FILE'] = FugitiveGitPath(fugitive#Find('.git/index', a:dir))
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
@@ -1823,11 +1831,11 @@ function! fugitive#Find(object, ...) abort
|
|||||||
let fdir = dir . '/'
|
let fdir = dir . '/'
|
||||||
let f = fdir . 'index'
|
let f = fdir . 'index'
|
||||||
if len($GIT_INDEX_FILE)
|
if len($GIT_INDEX_FILE)
|
||||||
let index_dir = substitute($GIT_INDEX_FILE, '[^/]\+$', '', '')
|
let index_dir = substitute(s:GitIndexFileEnv(), '[^/]\+$', '', '')
|
||||||
if s:cpath(index_dir, fdir)
|
if s:cpath(index_dir, fdir)
|
||||||
let f = FugitiveVimPath($GIT_INDEX_FILE)
|
let f = s:GitIndexFileEnv()
|
||||||
elseif s:cpath(resolve(FugitiveVimPath(index_dir)), fdir)
|
elseif s:cpath(resolve(index_dir), fdir)
|
||||||
let f = resolve(FugitiveVimPath($GIT_INDEX_FILE))
|
let f = resolve(s:GitIndexFileEnv())
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
elseif rev =~# '^:(\%(top\|top,literal\|literal,top\|literal\))'
|
elseif rev =~# '^:(\%(top\|top,literal\|literal,top\|literal\))'
|
||||||
@@ -2646,7 +2654,7 @@ function! fugitive#BufReadStatus(...) abort
|
|||||||
|
|
||||||
let cmd = [s:Dir()]
|
let cmd = [s:Dir()]
|
||||||
setlocal noreadonly modifiable nomodeline buftype=nowrite
|
setlocal noreadonly modifiable nomodeline buftype=nowrite
|
||||||
if amatch !~# '^fugitive:' && s:cpath(fnamemodify($GIT_INDEX_FILE !=# '' ? FugitiveVimPath($GIT_INDEX_FILE) : fugitive#Find('.git/index'), ':p')) !=# s:cpath(amatch)
|
if amatch !~# '^fugitive:' && s:cpath($GIT_INDEX_FILE !=# '' ? resolve(s:GitIndexFileEnv()) : fugitive#Find('.git/index')) !=# s:cpath(amatch)
|
||||||
let cmd += [{'env': {'GIT_INDEX_FILE': FugitiveGitPath(amatch)}}]
|
let cmd += [{'env': {'GIT_INDEX_FILE': FugitiveGitPath(amatch)}}]
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user