From f5a5234f224e729ed48b08a12727dbd6b3cb0481 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Mon, 16 May 2016 13:47:14 +0100 Subject: [PATCH] Allow configuration of git executable. --- autoload/gitgutter.vim | 4 ++-- autoload/gitgutter/debug.vim | 2 +- autoload/gitgutter/diff.vim | 6 +++--- autoload/gitgutter/utility.vim | 4 ++-- plugin/gitgutter.vim | 7 ++++++- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/autoload/gitgutter.vim b/autoload/gitgutter.vim index 9b76683..b0da84e 100644 --- a/autoload/gitgutter.vim +++ b/autoload/gitgutter.vim @@ -181,7 +181,7 @@ function! gitgutter#stage_hunk() abort call gitgutter#utility#warn('cursor is not in a hunk') else let diff_for_hunk = gitgutter#diff#generate_diff_for_hunk(diff, 'stage') - call gitgutter#utility#system(gitgutter#utility#command_in_directory_of_file('git apply --cached --unidiff-zero - '), diff_for_hunk) + call gitgutter#utility#system(gitgutter#utility#command_in_directory_of_file(g:gitgutter_git_executable.' apply --cached --unidiff-zero - '), diff_for_hunk) " refresh gitgutter's view of buffer silent execute "GitGutter" @@ -203,7 +203,7 @@ function! gitgutter#undo_hunk() abort call gitgutter#utility#warn('cursor is not in a hunk') else let diff_for_hunk = gitgutter#diff#generate_diff_for_hunk(diff, 'undo') - call gitgutter#utility#system(gitgutter#utility#command_in_directory_of_file('git apply --reverse --unidiff-zero - '), diff_for_hunk) + call gitgutter#utility#system(gitgutter#utility#command_in_directory_of_file(g:gitgutter_git_executable.' apply --reverse --unidiff-zero - '), diff_for_hunk) " reload file silent edit diff --git a/autoload/gitgutter/debug.vim b/autoload/gitgutter/debug.vim index ad96a90..594f044 100644 --- a/autoload/gitgutter/debug.vim +++ b/autoload/gitgutter/debug.vim @@ -47,7 +47,7 @@ function! gitgutter#debug#vim_version() endfunction function! gitgutter#debug#git_version() - let v = system('git --version') + let v = system(g:gitgutter_git_executable.' --version') call gitgutter#debug#output( substitute(v, '\n$', '', '') ) endfunction diff --git a/autoload/gitgutter/diff.vim b/autoload/gitgutter/diff.vim index 74f07d1..ea3ae28 100644 --- a/autoload/gitgutter/diff.vim +++ b/autoload/gitgutter/diff.vim @@ -58,7 +58,7 @@ function! gitgutter#diff#run_diff(realtime, preserve_full_diff) abort let bufnr = gitgutter#utility#bufnr() let tracked = getbufvar(bufnr, 'gitgutter_tracked') " i.e. tracked by git if !tracked - let cmd .= 'git ls-files --error-unmatch '.gitgutter#utility#shellescape(gitgutter#utility#filename()).' && (' + let cmd .= g:gitgutter_git_executable.' ls-files --error-unmatch '.gitgutter#utility#shellescape(gitgutter#utility#filename()).' && (' endif if a:realtime @@ -70,7 +70,7 @@ function! gitgutter#diff#run_diff(realtime, preserve_full_diff) abort let blob_file .= '.'.extension let buff_file .= '.'.extension endif - let cmd .= 'git show '.blob_name.' > '.blob_file.' && ' + let cmd .= g:gitgutter_git_executable.' show '.blob_name.' > '.blob_file.' && ' " Writing the whole buffer resets the '[ and '] marks and also the " 'modified' flag (if &cpoptions includes '+'). These are unwanted @@ -86,7 +86,7 @@ function! gitgutter#diff#run_diff(realtime, preserve_full_diff) abort call setpos("']", op_mark_end) endif - let cmd .= 'git' + let cmd .= g:gitgutter_git_executable if s:c_flag let cmd .= ' -c "diff.autorefreshindex=0"' endif diff --git a/autoload/gitgutter/utility.vim b/autoload/gitgutter/utility.vim index cb51973..2415b97 100644 --- a/autoload/gitgutter/utility.vim +++ b/autoload/gitgutter/utility.vim @@ -138,7 +138,7 @@ endfunction 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')) + let dir_path_relative_to_repo_root = gitgutter#utility#system(gitgutter#utility#command_in_directory_of_file(g:gitgutter_git_executable.' rev-parse --show-prefix')) let dir_path_relative_to_repo_root = gitgutter#utility#strip_trailing_new_line(dir_path_relative_to_repo_root) let file_path_relative_to_repo_root = dir_path_relative_to_repo_root . gitgutter#utility#filename() call setbufvar(s:bufnr, 'gitgutter_repo_relative_path', file_path_relative_to_repo_root) @@ -169,7 +169,7 @@ function! gitgutter#utility#strip_trailing_new_line(line) abort endfunction function! gitgutter#utility#git_version() abort - return matchstr(system('git --version'), '[0-9.]\+') + return matchstr(system(g:gitgutter_git_executable.' --version'), '[0-9.]\+') endfunction " True for git v1.7.2+. diff --git a/plugin/gitgutter.vim b/plugin/gitgutter.vim index af67de4..84f6ef8 100644 --- a/plugin/gitgutter.vim +++ b/plugin/gitgutter.vim @@ -1,6 +1,6 @@ scriptencoding utf-8 -if exists('g:loaded_gitgutter') || !executable('git') || !has('signs') || &cp +if exists('g:loaded_gitgutter') || !has('signs') || &cp finish endif let g:loaded_gitgutter = 1 @@ -51,6 +51,11 @@ call s:set('g:gitgutter_map_keys', 1) call s:set('g:gitgutter_avoid_cmd_prompt_on_windows', 1) call s:set('g:gitgutter_async', 1) call s:set('g:gitgutter_log', 0) +call s:set('g:gitgutter_git_executable', 'git') + +if !executable('git') + call gitgutter#utility#warn('cannot find git. Please set g:gitgutter_git_executable.') +endif call gitgutter#highlight#define_sign_column_highlight() call gitgutter#highlight#define_highlights()