mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-10 04:23:46 -05:00
Abort functions at first error.
This commit is contained in:
@@ -3,14 +3,14 @@ let s:using_xolox_shell = -1
|
||||
let s:exit_code = 0
|
||||
let s:fish = &shell =~# 'fish'
|
||||
|
||||
function! gitgutter#utility#warn(message)
|
||||
function! gitgutter#utility#warn(message) abort
|
||||
echohl WarningMsg
|
||||
echo 'vim-gitgutter: ' . a:message
|
||||
echohl None
|
||||
let v:warningmsg = a:message
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#warn_once(message, key)
|
||||
function! gitgutter#utility#warn_once(message, key) abort
|
||||
if empty(getbufvar(s:bufnr, a:key))
|
||||
call setbufvar(s:bufnr, a:key, '1')
|
||||
echohl WarningMsg
|
||||
@@ -22,7 +22,7 @@ endfunction
|
||||
|
||||
" Returns truthy when the buffer's file should be processed; and falsey when it shouldn't.
|
||||
" This function does not and should not make any system calls.
|
||||
function! gitgutter#utility#is_active()
|
||||
function! gitgutter#utility#is_active() abort
|
||||
return g:gitgutter_enabled &&
|
||||
\ !pumvisible() &&
|
||||
\ gitgutter#utility#is_file_buffer() &&
|
||||
@@ -30,11 +30,11 @@ function! gitgutter#utility#is_active()
|
||||
\ gitgutter#utility#not_git_dir()
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#not_git_dir()
|
||||
function! gitgutter#utility#not_git_dir() abort
|
||||
return gitgutter#utility#full_path_to_directory_of_file() !~ '[/\\]\.git\($\|[/\\]\)'
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#is_file_buffer()
|
||||
function! gitgutter#utility#is_file_buffer() abort
|
||||
return empty(getbufvar(s:bufnr, '&buftype'))
|
||||
endfunction
|
||||
|
||||
@@ -45,7 +45,7 @@ endfunction
|
||||
"
|
||||
" See:
|
||||
" https://github.com/tpope/vim-fugitive/blob/8f0b8edfbd246c0026b7a2388e1d883d579ac7f6/plugin/fugitive.vim#L29-L37
|
||||
function! gitgutter#utility#shellescape(arg)
|
||||
function! gitgutter#utility#shellescape(arg) abort
|
||||
if a:arg =~ '^[A-Za-z0-9_/.-]\+$'
|
||||
return a:arg
|
||||
elseif &shell =~# 'cmd' || gitgutter#utility#using_xolox_shell()
|
||||
@@ -55,7 +55,7 @@ function! gitgutter#utility#shellescape(arg)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#set_buffer(bufnr)
|
||||
function! gitgutter#utility#set_buffer(bufnr) abort
|
||||
let s:bufnr = a:bufnr
|
||||
let s:file = resolve(bufname(a:bufnr))
|
||||
endfunction
|
||||
@@ -68,43 +68,43 @@ function! gitgutter#utility#file()
|
||||
return s:file
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#filename()
|
||||
function! gitgutter#utility#filename() abort
|
||||
return fnamemodify(s:file, ':t')
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#extension()
|
||||
function! gitgutter#utility#extension() abort
|
||||
return fnamemodify(s:file, ':e')
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#full_path_to_directory_of_file()
|
||||
function! gitgutter#utility#full_path_to_directory_of_file() abort
|
||||
return fnamemodify(s:file, ':p:h')
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#directory_of_file()
|
||||
function! gitgutter#utility#directory_of_file() abort
|
||||
return fnamemodify(s:file, ':h')
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#exists_file()
|
||||
function! gitgutter#utility#exists_file() abort
|
||||
return filereadable(s:file)
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#has_unsaved_changes()
|
||||
function! gitgutter#utility#has_unsaved_changes() abort
|
||||
return getbufvar(s:bufnr, "&mod")
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#has_fresh_changes()
|
||||
function! gitgutter#utility#has_fresh_changes() abort
|
||||
return getbufvar(s:bufnr, 'changedtick') != getbufvar(s:bufnr, 'gitgutter_last_tick')
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#save_last_seen_change()
|
||||
function! gitgutter#utility#save_last_seen_change() abort
|
||||
call setbufvar(s:bufnr, 'gitgutter_last_tick', getbufvar(s:bufnr, 'changedtick'))
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#shell_error()
|
||||
function! gitgutter#utility#shell_error() abort
|
||||
return gitgutter#utility#using_xolox_shell() ? s:exit_code : v:shell_error
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#using_xolox_shell()
|
||||
function! gitgutter#utility#using_xolox_shell() abort
|
||||
if s:using_xolox_shell == -1
|
||||
if !g:gitgutter_avoid_cmd_prompt_on_windows
|
||||
let s:using_xolox_shell = 0
|
||||
@@ -119,7 +119,7 @@ function! gitgutter#utility#using_xolox_shell()
|
||||
return s:using_xolox_shell
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#system(cmd, ...)
|
||||
function! gitgutter#utility#system(cmd, ...) abort
|
||||
call gitgutter#debug#log(a:cmd, a:000)
|
||||
|
||||
if gitgutter#utility#using_xolox_shell()
|
||||
@@ -136,7 +136,7 @@ function! gitgutter#utility#system(cmd, ...)
|
||||
return output
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#file_relative_to_repo_root()
|
||||
function! gitgutter#utility#file_relative_to_repo_root() abort
|
||||
let file_path_relative_to_repo_root = getbufvar(s:bufnr, 'gitgutter_repo_relative_path')
|
||||
if empty(file_path_relative_to_repo_root)
|
||||
let dir_path_relative_to_repo_root = gitgutter#utility#system(gitgutter#utility#command_in_directory_of_file('git rev-parse --show-prefix'))
|
||||
@@ -147,11 +147,11 @@ function! gitgutter#utility#file_relative_to_repo_root()
|
||||
return file_path_relative_to_repo_root
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#command_in_directory_of_file(cmd)
|
||||
function! gitgutter#utility#command_in_directory_of_file(cmd) abort
|
||||
return 'cd '.gitgutter#utility#shellescape(gitgutter#utility#directory_of_file()) . (s:fish ? '; and ' : ' && ') . a:cmd
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#highlight_name_for_change(text)
|
||||
function! gitgutter#utility#highlight_name_for_change(text) abort
|
||||
if a:text ==# 'added'
|
||||
return 'GitGutterLineAdded'
|
||||
elseif a:text ==# 'removed'
|
||||
@@ -165,20 +165,20 @@ function! gitgutter#utility#highlight_name_for_change(text)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#strip_trailing_new_line(line)
|
||||
function! gitgutter#utility#strip_trailing_new_line(line) abort
|
||||
return substitute(a:line, '\n$', '', '')
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#git_version()
|
||||
function! gitgutter#utility#git_version() abort
|
||||
return matchstr(system('git --version'), '[0-9.]\+')
|
||||
endfunction
|
||||
|
||||
" True for git v1.7.2+.
|
||||
function! gitgutter#utility#git_supports_command_line_config_override()
|
||||
function! gitgutter#utility#git_supports_command_line_config_override() abort
|
||||
let [major, minor, patch; _] = split(gitgutter#utility#git_version(), '\.')
|
||||
return major > 1 || (major == 1 && minor > 7) || (minor == 7 && patch > 1)
|
||||
endfunction
|
||||
|
||||
function! gitgutter#utility#stringify(list)
|
||||
function! gitgutter#utility#stringify(list) abort
|
||||
return join(a:list, "\n")."\n"
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user