mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-09 20:13:46 -05:00
Use minimal file paths.
Since we start all external commands by cd'ing to the current file's directory, we can use the file's name instead of its full path. The exception is `git show :FILE` where we must use a path relative to the repo root for maximum git compatibility. It turns out `git rev-parse` takes a `--show-prefix` argument which makes our relative path calculation far simpler. Minimising files paths has these benefits: - Easier to inspect the generated commands. - Less opportunity for escaping problems. - Eliminates possible mismatches betwen absolute paths generated by git and absolute paths generated by Vim (crops up with msys/msys2 on Windows). Thanks to @suxpert for helping with this.
This commit is contained in:
@@ -5,7 +5,7 @@ let s:hunk_re = '^@@ -\(\d\+\),\?\(\d*\) +\(\d\+\),\?\(\d*\) @@'
|
||||
|
||||
function! diff#run_diff(realtime, use_external_grep)
|
||||
" Wrap compound command in parentheses to make Windows happy.
|
||||
let cmd = '(git ls-files --error-unmatch ' . utility#shellescape(utility#file()) . ' && ('
|
||||
let cmd = '(git ls-files --error-unmatch ' . utility#shellescape(utility#filename()) . ' && ('
|
||||
|
||||
if a:realtime
|
||||
let blob_name = ':' . utility#shellescape(utility#file_relative_to_repo_root())
|
||||
@@ -13,7 +13,7 @@ function! diff#run_diff(realtime, use_external_grep)
|
||||
let cmd .= 'git show ' . blob_name . ' > ' . blob_file .
|
||||
\ ' && diff -U0 ' . g:gitgutter_diff_args . ' ' . blob_file . ' - '
|
||||
else
|
||||
let cmd .= 'git diff --no-ext-diff --no-color -U0 ' . g:gitgutter_diff_args . ' ' . utility#shellescape(utility#file())
|
||||
let cmd .= 'git diff --no-ext-diff --no-color -U0 ' . g:gitgutter_diff_args . ' ' . utility#shellescape(utility#filename())
|
||||
endif
|
||||
|
||||
if a:use_external_grep && s:grep_available
|
||||
|
||||
Reference in New Issue
Block a user