diff --git a/README.md b/README.md index 1619b4e330b8662643175ebdead1eff711e8e4ce..2a6d48dd062cac491dece6aad66ad6fd4be54de6 100644 --- a/README.md +++ b/README.md @@ -269,6 +269,11 @@ To enable or disable vimagit plugin. Default value is 1. > let g:magit_enabled=[01] +#### g:magit_git_cmd + +Git command, may be simply simply "git" if git is in your path. Defualt is "git" +> let g:magit_git_cmd="git" + #### g:magit_show_help To disable chatty inline help in magit buffer (default 1) diff --git a/autoload/magit/git.vim b/autoload/magit/git.vim index 20918628f02e669f0388f2efbff448e5665b2e0f..29021b315ab67e7cf69395f9bc481d9226979880 100644 --- a/autoload/magit/git.vim +++ b/autoload/magit/git.vim @@ -1,8 +1,6 @@ -let s:git_cmd="GIT_CONFIG=/dev/null GIT_CONFIG_NOSYSTEM=1 XDG_CONFIG_HOME=/ git" - function! magit#git#get_version() if ( !exists("s:git_version") ) - let s:git_version = matchlist(system(s:git_cmd . " --version"), + let s:git_version = matchlist(system(g:magit_git_cmd . " --version"), \ 'git version \(\d\+\)\.\(\d\+\)\.\(\d\+\)\.\(\d\+\)\.\(g\x\+\)')[1:5] endif return s:git_version @@ -26,7 +24,7 @@ function! magit#git#get_status() " we can't use git status -z here, because system doesn't make the " difference between NUL and NL. -status z terminate entries with NUL, " instead of NF - let status_list=magit#utils#systemlist(s:git_cmd . " status --porcelain") + let status_list=magit#utils#systemlist(g:magit_git_cmd . " status --porcelain") for file_status_line in status_list let line_match = matchlist(file_status_line, '\(.\)\(.\) \%(.\{-\} -> \)\?"\?\(.\{-\}\)"\?$') let filename = line_match[3] @@ -44,7 +42,7 @@ function! magit#git#is_work_tree(path) try call magit#utils#lcd(a:path) let top_dir=magit#utils#strip( - \ system(s:git_cmd . " rev-parse --show-toplevel")) . "/" + \ system(g:magit_git_cmd . " rev-parse --show-toplevel")) . "/" if ( v:shell_error != 0 ) return '' endif @@ -62,11 +60,11 @@ function! magit#git#set_top_dir(path) try call magit#utils#lcd(a:path) let top_dir=magit#utils#strip( - \ system(s:git_cmd . " rev-parse --show-toplevel")) . "/" + \ system(g:magit_git_cmd . " rev-parse --show-toplevel")) . "/" if ( v:shell_error != 0 ) throw "magit: git-show-toplevel error: " . top_dir endif - let git_dir=magit#utils#strip(system(s:git_cmd . " rev-parse --git-dir")) . "/" + let git_dir=magit#utils#strip(system(g:magit_git_cmd . " rev-parse --git-dir")) . "/" if ( v:shell_error != 0 ) throw "magit: git-git-dir error: " . git_dir endif @@ -108,7 +106,7 @@ endfunction function! magit#git#git_diff(filename, status, mode) let dev_null = ( a:status == '?' ) ? "/dev/null " : "" let staged_flag = ( a:mode == 'staged' ) ? "--staged" : "" - let git_cmd=s:git_cmd . " diff --no-ext-diff " . staged_flag . + let git_cmd=g:magit_git_cmd . " diff --no-ext-diff " . staged_flag . \ " --no-color -p -- " . dev_null . " " \ . a:filename silent let diff_list=magit#utils#systemlist(git_cmd) @@ -137,7 +135,7 @@ endfunction function! magit#git#sub_check(submodule, check_level) let ignore_flag = ( a:check_level == 'modified' ) ? \ '--ignore-submodules=untracked' : '' - let git_cmd=s:git_cmd . " status --porcelain " . ignore_flag . " " . a:submodule + let git_cmd=g:magit_git_cmd . " status --porcelain " . ignore_flag . " " . a:submodule return ( !empty(magit#utils#systemlist(git_cmd)) ) endfunction @@ -148,7 +146,7 @@ endfunction " param[in] mode: can be staged or unstaged function! magit#git#git_sub_summary(filename, mode) let staged_flag = ( a:mode == 'staged' ) ? " --cached " : " --files " - let git_cmd=s:git_cmd . " submodule summary " . staged_flag . " HEAD " + let git_cmd=g:magit_git_cmd . " submodule summary " . staged_flag . " HEAD " \ .a:filename silent let diff_list=magit#utils#systemlist(git_cmd) if ( empty(diff_list) ) @@ -173,7 +171,7 @@ endfunction " message is raised. " param[in] filemane: it must be quoted if it contains spaces function! magit#git#git_add(filename) - let git_cmd=s:git_cmd . " add --no-ignore-removal -- " . a:filename + let git_cmd=g:magit_git_cmd . " add --no-ignore-removal -- " . a:filename silent let git_result=magit#utils#system(git_cmd) if ( v:shell_error != 0 ) echohl WarningMsg @@ -189,7 +187,7 @@ endfunction " message is raised. " param[in] filemane: it must be quoted if it contains spaces function! magit#git#git_checkout(filename) - let git_cmd=s:git_cmd . " checkout -- " . a:filename + let git_cmd=g:magit_git_cmd . " checkout -- " . a:filename silent let git_result=magit#utils#system(git_cmd) if ( v:shell_error != 0 ) echohl WarningMsg @@ -205,7 +203,7 @@ endfunction " message is raised. " param[in] filemane: it must be quoted if it contains spaces function! magit#git#git_reset(filename) - let git_cmd=s:git_cmd . " reset HEAD -- " . a:filename + let git_cmd=g:magit_git_cmd . " reset HEAD -- " . a:filename silent let git_result=magit#utils#system(git_cmd) if ( v:shell_error != 0 ) echohl WarningMsg @@ -227,7 +225,7 @@ function! magit#git#git_apply(header, selection) if ( selection[-1] !~ '^$' ) let selection += [ '' ] endif - let git_cmd=s:git_cmd . " apply --recount --no-index --cached -" + let git_cmd=g:magit_git_cmd . " apply --recount --no-index --cached -" silent let git_result=magit#utils#system(git_cmd, selection) if ( v:shell_error != 0 ) echohl WarningMsg @@ -256,7 +254,7 @@ function! magit#git#git_unapply(header, selection, mode) let selection += [ '' ] endif silent let git_result=magit#utils#system( - \ s:git_cmd . " apply --recount --no-index " . cached_flag . " --reverse - ", + \ g:magit_git_cmd . " apply --recount --no-index " . cached_flag . " --reverse - ", \ selection) if ( v:shell_error != 0 ) echohl WarningMsg @@ -269,5 +267,5 @@ function! magit#git#git_unapply(header, selection, mode) endfunction function! magit#git#submodule_status() - return system(s:git_cmd . " submodule status") + return system(g:magit_git_cmd . " submodule status") endfunction diff --git a/doc/vimagit.txt b/doc/vimagit.txt index d64139c812877d97362c22ec6a4370b25e38102d..394c267c278e4201307bc6728d9f7e6a8779a5db 100644 --- a/doc/vimagit.txt +++ b/doc/vimagit.txt @@ -307,6 +307,11 @@ To enable or disable vimagit plugin. Default value is 1. let g:magit_enabled=[01] + *vimagit-g:magit_git_cmd* + +Git command, may be simply simply "git" if git is in your path. Defualt is "git" +let g:magit_git_cmd="git" + *vimagit-g:magit_show_help* To disable chatty inline help in magit buffer (default 1) let g:magit_show_help=[01] diff --git a/plugin/magit.vim b/plugin/magit.vim index 2c3505ee3a6cd592abddb3fcb652cfb00e3f98d4..271792ebac4ee9daf8800084eaaa9f16c24f7c62 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -50,6 +50,8 @@ let g:magit_discard_untracked_do_delete = get(g:, 'magit_discard_untracked_do_de let g:magit_refresh_gitgutter = get(g:, 'magit_refresh_gitgutter', 1) let g:magit_warning_max_lines = get(g:, 'magit_warning_max_lines', 10000) +let g:magit_git_cmd = get(g:, 'magit_git_cmd' , "git") + execute "nnoremap <silent> " . g:magit_show_magit_mapping . " :call magit#show_magit('v')<cr>" if ( g:magit_refresh_gitgutter == 1 ) @@ -127,8 +129,8 @@ function! s:mg_get_info() silent put =g:magit_sections.info silent put =magit#utils#underline(g:magit_sections.info) silent put ='' - let branch=magit#utils#system("git rev-parse --abbrev-ref HEAD") - let commit=magit#utils#system("git show -s --oneline") + let branch=magit#utils#system(g:magit_git_cmd . " rev-parse --abbrev-ref HEAD") + let commit=magit#utils#system(g:magit_git_cmd . " show -s --oneline") silent put =g:magit_section_info.cur_repo . ': ' . magit#git#top_dir() silent put =g:magit_section_info.cur_branch . ': ' . branch silent put =g:magit_section_info.cur_commit . ': ' . commit @@ -202,7 +204,7 @@ endfunction " WARNING: this function writes in file, it should only be called through " protected functions like magit#update_buffer function! s:mg_get_stashes() - silent! let stash_list=magit#utils#systemlist("git stash list") + silent! let stash_list=magit#utils#systemlist(g:magit_git_cmd . " stash list") if ( v:shell_error != 0 ) echoerr "Git error: " . stash_list endif @@ -240,9 +242,11 @@ function! s:mg_get_commit_section() let git_dir=magit#git#git_dir() " refresh the COMMIT_EDITMSG file if ( b:magit_current_commit_mode == 'CC' ) - silent! call magit#utils#system("GIT_EDITOR=/bin/false git commit -e 2> /dev/null") + silent! call magit#utils#system("GIT_EDITOR=/bin/false " . + \ g:magit_git_cmd . " commit -e 2> /dev/null") elseif ( b:magit_current_commit_mode == 'CA' ) - silent! call magit#utils#system("GIT_EDITOR=/bin/false git commit --amend -e 2> /dev/null") + silent! call magit#utils#system("GIT_EDITOR=/bin/false " . + \ g:magit_git_cmd . " commit --amend -e 2> /dev/null") endif if ( filereadable(git_dir . 'COMMIT_EDITMSG') ) let comment_char=<SID>mg_comment_char() @@ -256,7 +260,8 @@ endfunction " s:mg_comment_char: this function gets the commentChar from git config function! s:mg_comment_char() silent! let git_result=magit#utils#strip( - \ magit#utils#system("git config --get core.commentChar")) + \ magit#utils#system(g:magit_git_cmd . + \" config --get core.commentChar")) if ( v:shell_error != 0 ) return '#' else @@ -330,15 +335,16 @@ endfunction " return no function! s:mg_git_commit(mode) abort if ( a:mode == 'CF' ) - silent let git_result=magit#utils#system("git commit --amend -C HEAD") + silent let git_result=magit#utils#system(g:magit_git_cmd . + \ " commit --amend -C HEAD") else let commit_msg=s:mg_get_commit_msg() let amend_flag="" if ( a:mode == 'CA' ) let amend_flag=" --amend " endif - silent! let git_result=magit#utils#system( - \ "git commit " . amend_flag . " --file - ", commit_msg) + silent! let git_result=magit#utils#system(g:magit_git_cmd . + \ " commit " . amend_flag . " --file - ", commit_msg) endif if ( v:shell_error != 0 ) echoerr "Git error: " . git_result