diff --git a/autoload/magit/utils.vim b/autoload/magit/utils.vim index 0b1c8a47ab7c2a72935dbadf438a3ef6b16bf5d6..767aef80c495400c4874fceaa1fbb0d0f7fadd05 100644 --- a/autoload/magit/utils.vim +++ b/autoload/magit/utils.vim @@ -33,6 +33,31 @@ function! magit#utils#git_dir() return s:magit_git_dir endfunction +" magit#utils#git_add: helper function to add a whole file +" nota: when git fail (due to misformated patch for example), an error +" message is raised. +" param[in] filemane: it must be quoted if it contains spaces +function! magit#utils#git_add(filename) + let git_cmd="git add -- " . a:filename + silent let git_result=magit#utils#system(git_cmd) + if ( v:shell_error != 0 ) + echoerr "Git error: " . git_result + echoerr "Git cmd: " . git_cmd + endif +endfunction + +" magit#utils#git_reset: helper function to add a whole file +" nota: when git fail (due to misformated patch for example), an error +" message is raised. +" param[in] filemane: it must be quoted if it contains spaces +function! magit#utils#git_reset(filename) + let git_cmd="git reset -- " . a:filename + silent let git_result=magit#utils#system(git_cmd) + if ( v:shell_error != 0 ) + echoerr "Git error: " . git_result + echoerr "Git cmd: " . git_cmd + endif +endfunction " magit#utils#git_apply: helper function to stage a selection " nota: when git fail (due to misformated patch for example), an error diff --git a/plugin/magit.vim b/plugin/magit.vim index 3461bf040e3c3b1870875a159b476ccc726adb49..44fc02bce46b528b91b8bbccd4f905bd62e46b07 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -677,15 +677,13 @@ function! magit#stage_block(selection, discard) abort if ( a:discard == 0 ) if ( section == 'unstaged' ) if ( file.must_be_added() ) - call magit#utils#system('git add ' . - \ magit#utils#add_quotes(filename)) + call magit#utils#git_add(magit#utils#add_quotes(filename)) else call magit#utils#git_apply(header, a:selection) endif elseif ( section == 'staged' ) if ( file.must_be_added() ) - call magit#utils#system('git reset ' . - \ magit#utils#add_quotes(filename)) + call magit#utils#git_reset(magit#utils#add_quotes(filename)) else call magit#utils#git_unapply(header, a:selection, 'staged') endif