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:
Tim Pope
2021-08-22 22:35:06 -04:00
parent 89ab2d95cd
commit a41810fa86

View File

@@ -493,14 +493,16 @@ 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)
else
let a:cmd[i] = fugitive#Path(bufname(a:cmd[i]), ':(top,literal)', a:dir)
endif endif
endfor endfor
if split < 0 if split < 0
@@ -508,8 +510,12 @@ function! s:PreparePathArgs(cmd, dir, literal) abort
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)
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)
elseif a:literal 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