Skip to content
Snippets Groups Projects
Commit d77693b6 authored by Jerome Reybert's avatar Jerome Reybert
Browse files

autoload/magit/utils.vim: add git_add and git_reset helper functions

parent c10c9cad
No related branches found
No related tags found
No related merge requests found
...@@ -33,6 +33,31 @@ function! magit#utils#git_dir() ...@@ -33,6 +33,31 @@ function! magit#utils#git_dir()
return s:magit_git_dir return s:magit_git_dir
endfunction 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 " magit#utils#git_apply: helper function to stage a selection
" nota: when git fail (due to misformated patch for example), an error " nota: when git fail (due to misformated patch for example), an error
......
...@@ -677,15 +677,13 @@ function! magit#stage_block(selection, discard) abort ...@@ -677,15 +677,13 @@ function! magit#stage_block(selection, discard) abort
if ( a:discard == 0 ) if ( a:discard == 0 )
if ( section == 'unstaged' ) if ( section == 'unstaged' )
if ( file.must_be_added() ) if ( file.must_be_added() )
call magit#utils#system('git add ' . call magit#utils#git_add(magit#utils#add_quotes(filename))
\ magit#utils#add_quotes(filename))
else else
call magit#utils#git_apply(header, a:selection) call magit#utils#git_apply(header, a:selection)
endif endif
elseif ( section == 'staged' ) elseif ( section == 'staged' )
if ( file.must_be_added() ) if ( file.must_be_added() )
call magit#utils#system('git reset ' . call magit#utils#git_reset(magit#utils#add_quotes(filename))
\ magit#utils#add_quotes(filename))
else else
call magit#utils#git_unapply(header, a:selection, 'staged') call magit#utils#git_unapply(header, a:selection, 'staged')
endif endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment