mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-12 21:33:53 -05:00
Better support for --no-literal-pathspecs
When given an argument list including --no-literal-pathspecs and a buffer number, convert the buffer number to an argument by prepending ":(top,literal)" to the filename rather than "./". This allows operating on file names that include special characters like "*" and "?".
This commit is contained in:
@@ -493,23 +493,29 @@ function! s:HasOpt(args, ...) abort
|
|||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:PreparePathArgs(cmd, dir, literal) abort
|
function! s:PreparePathArgs(cmd, dir, literal, explicit) abort
|
||||||
if a:literal
|
if !a:explicit
|
||||||
call insert(a:cmd, '--literal-pathspecs')
|
call insert(a:cmd, '--literal-pathspecs')
|
||||||
endif
|
endif
|
||||||
let split = index(a:cmd, '--')
|
let split = index(a:cmd, '--')
|
||||||
for i in range(split < 0 ? len(a:cmd) : split)
|
for i in range(split < 0 ? len(a:cmd) : split)
|
||||||
if type(a:cmd[i]) == type(0)
|
if a:literal
|
||||||
let a:cmd[i] = fugitive#Path(bufname(a:cmd[i]), './', a:dir)
|
let a:cmd[i] = fugitive#Path(bufname(a:cmd[i]), './', a:dir)
|
||||||
endif
|
else
|
||||||
|
let a:cmd[i] = fugitive#Path(bufname(a:cmd[i]), ':(top,literal)', a:dir)
|
||||||
|
endif
|
||||||
endfor
|
endfor
|
||||||
if split < 0
|
if split < 0
|
||||||
return a:cmd
|
return a:cmd
|
||||||
endif
|
endif
|
||||||
for i in range(split + 1, len(a:cmd) - 1)
|
for i in range(split + 1, len(a:cmd) - 1)
|
||||||
if type(a:cmd[i]) == type(0)
|
if type(a:cmd[i]) == type(0)
|
||||||
let a:cmd[i] = fugitive#Path(bufname(a:cmd[i]), './', a:dir)
|
if a:literal
|
||||||
elseif a:literal
|
let a:cmd[i] = fugitive#Path(bufname(a:cmd[i]), './', a:dir)
|
||||||
|
else
|
||||||
|
let a:cmd[i] = fugitive#Path(bufname(a:cmd[i]), ':(top,literal)', a:dir)
|
||||||
|
endif
|
||||||
|
elseif !a:explicit
|
||||||
let a:cmd[i] = fugitive#Path(a:cmd[i], './', a:dir)
|
let a:cmd[i] = fugitive#Path(a:cmd[i], './', a:dir)
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
@@ -557,6 +563,8 @@ function! fugitive#PrepareDirEnvGitFlagsArgs(...) abort
|
|||||||
let env = {}
|
let env = {}
|
||||||
endif
|
endif
|
||||||
let autoenv = {}
|
let autoenv = {}
|
||||||
|
let explicit_pathspec_option = 0
|
||||||
|
let literal_pathspecs = 1
|
||||||
let i = 0
|
let i = 0
|
||||||
let arg_count = 0
|
let arg_count = 0
|
||||||
while i < len(cmd)
|
while i < len(cmd)
|
||||||
@@ -588,6 +596,7 @@ function! fugitive#PrepareDirEnvGitFlagsArgs(...) abort
|
|||||||
endif
|
endif
|
||||||
let i += 2
|
let i += 2
|
||||||
elseif cmd[i] =~# '^--.*pathspecs$'
|
elseif cmd[i] =~# '^--.*pathspecs$'
|
||||||
|
let literal_pathspecs = (cmd[i] ==# '--literal-pathspecs')
|
||||||
let explicit_pathspec_option = 1
|
let explicit_pathspec_option = 1
|
||||||
let i += 1
|
let i += 1
|
||||||
elseif cmd[i] !~# '^-'
|
elseif cmd[i] !~# '^-'
|
||||||
@@ -603,7 +612,7 @@ function! fugitive#PrepareDirEnvGitFlagsArgs(...) abort
|
|||||||
if !has_key(env, 'GIT_INDEX_FILE')
|
if !has_key(env, 'GIT_INDEX_FILE')
|
||||||
call s:PrepareEnv(autoenv, dir)
|
call s:PrepareEnv(autoenv, dir)
|
||||||
endif
|
endif
|
||||||
call s:PreparePathArgs(cmd, dir, !exists('explicit_pathspec_option'))
|
call s:PreparePathArgs(cmd, dir, literal_pathspecs, explicit_pathspec_option)
|
||||||
return [s:GitDir(dir), env, extend(autoenv, env), git, cmd[0 : -arg_count-1], arg_count ? cmd[-arg_count : -1] : []]
|
return [s:GitDir(dir), env, extend(autoenv, env), git, cmd[0 : -arg_count-1], arg_count ? cmd[-arg_count : -1] : []]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user