1
0
mirror of https://github.com/amix/vimrc synced 2025-06-30 20:05:01 +08:00

Updated plugins

This commit is contained in:
Amir
2024-01-07 16:14:20 +01:00
parent 86762cf230
commit f676f799e7
172 changed files with 3227 additions and 1204 deletions

View File

@ -18,6 +18,7 @@ Features:
* Stage partial hunks.
* Provides a hunk text object.
* Diffs against index (default) or any commit.
* Handles file moves / renames.
* Heeds git's "assume unchanged" bit.
* Allows folding all unchanged text.
* Provides fold text showing whether folded lines have been changed.
@ -29,6 +30,7 @@ Features:
* Fully customisable (signs, sign column, line (number) highlights, mappings, extra git-diff arguments, etc).
* Can be toggled on/off, globally or per buffer.
* Preserves signs from other plugins.
* Does the right thing when viewing revisions with [fugitive](https://github.com/tpope/vim-fugitive)'s `:0Gclog`.
* Easy to integrate diff stats into status line; built-in integration with [vim-airline](https://github.com/bling/vim-airline/).
* Works with fish shell (in addition to the usual shells).

View File

@ -46,8 +46,6 @@ function! gitgutter#process_buffer(bufnr, force) abort
call gitgutter#debug#log('Not tracked: '.gitgutter#utility#file(a:bufnr))
catch /gitgutter assume unchanged/
call gitgutter#debug#log('Assume unchanged: '.gitgutter#utility#file(a:bufnr))
catch /gitgutter file unknown in base/
let diff = gitgutter#diff#hunk_header_showing_every_line_added(a:bufnr)
catch /gitgutter diff failed/
call gitgutter#debug#log('Diff failed: '.gitgutter#utility#file(a:bufnr))
call gitgutter#hunk#reset(a:bufnr)
@ -197,6 +195,7 @@ function! s:clear(bufnr)
call gitgutter#hunk#reset(a:bufnr)
call s:reset_tick(a:bufnr)
call gitgutter#utility#setbufvar(a:bufnr, 'path', '')
call gitgutter#utility#setbufvar(a:bufnr, 'basepath', '')
endfunction
@ -223,13 +222,13 @@ function! gitgutter#quickfix(current_file)
let lnum = 0
for line in diff
if line =~ '^diff --git [^"]'
let paths = line[11:]
let mid = (len(paths) - 1) / 2
let [fnamel, fnamer] = [paths[:mid-1], paths[mid+1:]]
let fname = fnamel ==# fnamer ? fnamel : fnamel[2:]
" No quotation mark therefore no spaces in filenames
let [fnamel, fnamer] = split(line)[2:3]
let fname = fnamel ==# fnamer ? fnamer : fnamer[2:]
elseif line =~ '^diff --git "'
" Quotation mark therefore do not split on space
let [_, fnamel, _, fnamer] = split(line, '"')
let fname = fnamel ==# fnamer ? fnamel : fnamel[2:]
let fname = fnamel ==# fnamer ? fnamer : fnamer[2:]
elseif line =~ '^diff --cc [^"]'
let fname = line[10:]
elseif line =~ '^diff --cc "'
@ -251,7 +250,6 @@ endfunction
function! gitgutter#difforig()
let bufnr = bufnr('')
let path = gitgutter#utility#repo_path(bufnr, 1)
let filetype = &filetype
vertical new
@ -259,7 +257,7 @@ function! gitgutter#difforig()
let &filetype = filetype
if g:gitgutter_diff_relative_to ==# 'index'
let index_name = gitgutter#utility#get_diff_base(bufnr).':'.path
let index_name = gitgutter#utility#get_diff_base(bufnr).':'.gitgutter#utility#base_path(bufnr)
let cmd = gitgutter#utility#cd_cmd(bufnr,
\ gitgutter#git().' --no-pager show '.index_name
\ )
@ -267,7 +265,7 @@ function! gitgutter#difforig()
" gitgutter#utility's use_known_shell() / restore_shell() functions.
silent! execute "read ++edit !" cmd
else
silent! execute "read ++edit" path
silent! execute "read ++edit" gitgutter#utility#repo_path(bufnr, 1)
endif
0d_

View File

@ -4,14 +4,6 @@ let s:nomodeline = (v:version > 703 || (v:version == 703 && has('patch442'))) ?
let s:hunk_re = '^@@ -\(\d\+\),\?\(\d*\) +\(\d\+\),\?\(\d*\) @@'
" True for git v1.7.2+.
function! s:git_supports_command_line_config_override() abort
call gitgutter#utility#system(gitgutter#git().' -c foo.bar=baz --version')
return !v:shell_error
endfunction
let s:c_flag = s:git_supports_command_line_config_override()
let s:temp_from = tempname()
let s:temp_buffer = tempname()
let s:counter = 0
@ -81,20 +73,6 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
throw 'gitgutter assume unchanged'
endif
" If we are diffing against a specific branch/commit, handle the case
" where a file exists on the current branch but not in/at the diff base.
" We have to handle it here because the approach below (using git-show)
" doesn't work for this case.
if !empty(g:gitgutter_diff_base)
let index_name = gitgutter#utility#get_diff_base(a:bufnr).':'.gitgutter#utility#repo_path(a:bufnr, 1)
let cmd = gitgutter#git().' --no-pager show '.index_name
let cmd = gitgutter#utility#cd_cmd(a:bufnr, cmd)
call gitgutter#utility#system(cmd)
if v:shell_error
throw 'gitgutter file unknown in base'
endif
endif
" Wrap compound commands in parentheses to make Windows happy.
" bash doesn't mind the parentheses.
let cmd = '('
@ -137,8 +115,8 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
endif
" Write file from index to temporary file.
let index_name = gitgutter#utility#get_diff_base(a:bufnr).':'.gitgutter#utility#repo_path(a:bufnr, 1)
let cmd .= gitgutter#git().' --no-pager show --textconv '.index_name.' > '.from_file.' && '
let index_name = gitgutter#utility#get_diff_base(a:bufnr).':'.gitgutter#utility#base_path(a:bufnr)
let cmd .= gitgutter#git().' --no-pager show --textconv '.index_name.' > '.from_file.' || exit 0) && ('
elseif a:from ==# 'working_tree'
let from_file = gitgutter#utility#repo_path(a:bufnr, 1)
@ -146,7 +124,7 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
" Call git-diff.
let cmd .= gitgutter#git().' --no-pager'
if s:c_flag
if gitgutter#utility#git_supports_command_line_config_override()
let cmd .= ' -c "diff.autorefreshindex=0"'
let cmd .= ' -c "diff.noprefix=false"'
let cmd .= ' -c "core.safecrlf=false"'
@ -176,9 +154,9 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
return 'async'
else
let diff = gitgutter#utility#system(cmd)
let [diff, error_code] = gitgutter#utility#system(cmd)
if v:shell_error
if error_code
call gitgutter#debug#log(diff)
throw 'gitgutter diff failed'
endif
@ -390,12 +368,6 @@ function! gitgutter#diff#hunk_diff(bufnr, full_diff, ...)
endfunction
function! gitgutter#diff#hunk_header_showing_every_line_added(bufnr)
let buf_line_count = getbufinfo(a:bufnr)[0].linecount
return '@@ -0,0 +1,'.buf_line_count.' @@'
endfunction
function! s:write_buffer(bufnr, file)
let bufcontents = getbufline(a:bufnr, 1, '$')

View File

@ -309,7 +309,7 @@ function! s:stage(hunk_diff)
let cmd = gitgutter#utility#cd_cmd(bufnr,
\ gitgutter#git().' add '.
\ gitgutter#utility#shellescape(gitgutter#utility#filename(bufnr)))
call gitgutter#utility#system(cmd)
let [_, error_code] = gitgutter#utility#system(cmd)
else
return
endif
@ -317,12 +317,12 @@ function! s:stage(hunk_diff)
else
let diff = s:adjust_header(bufnr, a:hunk_diff)
" Apply patch to index.
call gitgutter#utility#system(
let [_, error_code] = gitgutter#utility#system(
\ gitgutter#utility#cd_cmd(bufnr, gitgutter#git().' apply --cached --unidiff-zero - '),
\ diff)
endif
if v:shell_error
if error_code
call gitgutter#utility#warn('Patch does not apply')
else
if exists('#User#GitGutterStage')

View File

@ -6,6 +6,15 @@ function! gitgutter#utility#supports_overscore_sign()
endif
endfunction
" True for git v1.7.2+.
function! gitgutter#utility#git_supports_command_line_config_override() abort
if !exists('s:c_flag')
let [_, error_code] = gitgutter#utility#system(gitgutter#git().' -c foo.bar=baz --version')
let s:c_flag = !error_code
endif
return s:c_flag
endfunction
function! gitgutter#utility#setbufvar(buffer, varname, val)
let buffer = +a:buffer
" Default value for getbufvar() was introduced in Vim 7.3.831.
@ -93,10 +102,13 @@ function! gitgutter#utility#system(cmd, ...) abort
call gitgutter#debug#log(a:cmd, a:000)
call s:use_known_shell()
let prev_error_code = v:shell_error
silent let output = (a:0 == 0) ? system(a:cmd) : system(a:cmd, a:1)
let error_code = v:shell_error
silent call system('exit ' . prev_error_code)
call s:restore_shell()
return output
return [output, error_code]
endfunction
function! gitgutter#utility#has_repo_path(bufnr)
@ -161,9 +173,9 @@ function! gitgutter#utility#set_repo_path(bufnr, continuation) abort
return 'async'
endif
let listing = gitgutter#utility#system(cmd)
let [listing, error_code] = gitgutter#utility#system(cmd)
if v:shell_error
if error_code
call gitgutter#utility#setbufvar(a:bufnr, 'path', -2)
return
endif
@ -184,7 +196,7 @@ function! gitgutter#utility#clean_smudge_filter_applies(bufnr)
let cmd = gitgutter#utility#cd_cmd(a:bufnr,
\ gitgutter#git().' check-attr filter -- '.
\ gitgutter#utility#shellescape(gitgutter#utility#filename(a:bufnr)))
let out = gitgutter#utility#system(cmd)
let [out, _] = gitgutter#utility#system(cmd)
let filtered = out !~ 'unspecified'
call gitgutter#utility#setbufvar(a:bufnr, 'filter', filtered)
endif
@ -233,6 +245,87 @@ function! gitgutter#utility#get_diff_base(bufnr)
return g:gitgutter_diff_base
endfunction
" Returns the original path (shellescaped) at the buffer's diff base.
function! gitgutter#utility#base_path(bufnr)
let diffbase = gitgutter#utility#get_diff_base(a:bufnr)
" If we already know the original path at this diff base, return it.
let basepath = gitgutter#utility#getbufvar(a:bufnr, 'basepath', '')
if !empty(basepath)
" basepath is diffbase:path
" Note that path can also contain colons.
" List destructuring / unpacking where the remaining items are assigned
" to a single variable (:help let-unpack) is only available in v8.2.0540.
let parts = split(basepath, ':', 1)
let base = parts[0]
let bpath = join(parts[1:], ':')
if base == diffbase
return gitgutter#utility#shellescape(bpath)
endif
endif
" Obtain buffers' paths.
let current_paths = {}
for bufnr in range(1, bufnr('$') + 1)
if gitgutter#utility#has_repo_path(bufnr)
let current_paths[gitgutter#utility#repo_path(bufnr, 0)] = bufnr
endif
endfor
" Get a list of file renames at the buffer's diff base.
" Store the original paths on any corresponding buffers.
" If the buffer's file was one of them, return its original path.
let op = ''
let renames = s:obtain_file_renames(a:bufnr, diffbase)
for [current, original] in items(renames)
if has_key(current_paths, current)
let bufnr = current_paths[current]
let basepath = diffbase.':'.original
call gitgutter#utility#setbufvar(bufnr, 'basepath', basepath)
if bufnr == a:bufnr
let op = original
endif
endif
endfor
if !empty(op)
return gitgutter#utility#shellescape(op)
endif
" Buffer's file was not renamed, so store current path and return it.
let current_path = gitgutter#utility#repo_path(a:bufnr, 0)
let basepath = diffbase.':'.current_path
call gitgutter#utility#setbufvar(a:bufnr, 'basepath', basepath)
return gitgutter#utility#shellescape(current_path)
endfunction
" Returns a dict of current path to original path at the given base.
function! s:obtain_file_renames(bufnr, base)
let renames = {}
let cmd = gitgutter#git()
if gitgutter#utility#git_supports_command_line_config_override()
let cmd .= ' -c "core.safecrlf=false"'
endif
let cmd .= ' diff --diff-filter=R --name-status '.a:base
let [out, error_code] = gitgutter#utility#system(gitgutter#utility#cd_cmd(a:bufnr, cmd))
if error_code
" Assume the problem is the diff base.
call gitgutter#utility#warn('g:gitgutter_diff_base ('.a:base.') is invalid')
return {}
endif
for line in split(out, '\n')
let fields = split(line)
if len(fields) != 3
call gitgutter#utility#warn('gitgutter: unable to list renamed files: '.line)
return {}
endif
let [original, current] = fields[1:]
let renames[current] = original
endfor
return renames
endfunction
function! s:abs_path(bufnr, shellesc)
let p = resolve(expand('#'.a:bufnr.':p'))

View File

@ -52,6 +52,7 @@ endfunction
"
function SetUp()
let g:gitgutter_diff_base = ''
call system("git init ".s:test_repo.
\ " && cd ".s:test_repo.
\ " && cp ../.gitconfig .".
@ -195,6 +196,20 @@ function Test_filename_with_equals()
endfunction
function Test_filename_with_colon()
call system('touch fix:ture.txt && git add fix:ture.txt')
edit fix:ture.txt
normal ggo*
call s:trigger_gitgutter()
let expected = [
\ {'lnum': 1, 'name': 'GitGutterLineAdded'},
\ {'lnum': 2, 'name': 'GitGutterLineAdded'}
\ ]
call s:assert_signs(expected, 'fix:ture.txt')
endfunction
function Test_filename_with_square_brackets()
call system('touch fix[tu]re.txt && git add fix[tu]re.txt')
edit fix[tu]re.txt
@ -280,6 +295,29 @@ function Test_saveas()
endfunction
function Test_file_mv()
call system('git mv fixture.txt fixture_moved.txt')
edit fixture_moved.txt
normal ggo*
call s:trigger_gitgutter()
let expected = [{'lnum': 2, 'name': 'GitGutterLineAdded'}]
call s:assert_signs(expected, 'fixture_moved.txt')
write
call system('git add fixture_moved.txt && git commit -m "moved and edited"')
GitGutterDisable
GitGutterEnable
let expected = []
call s:assert_signs(expected, 'fixture_moved.txt')
GitGutterDisable
let g:gitgutter_diff_base = 'HEAD^'
GitGutterEnable
let expected = [{'lnum': 2, 'name': 'GitGutterLineAdded'}]
call s:assert_signs(expected, 'fixture_moved.txt')
endfunction
" FIXME: this test fails when it is the first (or only) test to be run
function Test_follow_symlink()
let tmp = 'symlink'
@ -382,8 +420,7 @@ endfunction
function Test_file_unknown_in_base()
let starting_branch = system('git branch --show-current')
let starting_branch = 'main'
let starting_branch = split(system('git branch --show-current'))[0]
call system('git checkout -b some-feature')
let tmp = 'file-on-this-branch-only.tmp'
call system('echo "hi" > '.tmp.' && git add '.tmp)
@ -396,6 +433,27 @@ function Test_file_unknown_in_base()
endfunction
function Test_v_shell_error_not_clobbered()
" set gitgutter up to generate a shell error
let starting_branch = split(system('git branch --show-current'))[0]
call system('git checkout -b some-feature')
let tmp = 'file-on-this-branch-only.tmp'
call system('echo "hi" > '.tmp.' && git add '.tmp)
execute 'edit '.tmp
let g:gitgutter_diff_base = starting_branch
" run a successful shell command
silent !echo foobar >/dev/null
" run gitgutter
GitGutter
call assert_equal(0, v:shell_error)
let g:gitgutter_diff_base = ''
endfunction
function Test_hunk_outside_noop()
5
GitGutterStageHunk