From d758175454e9d33ec04b809c2a80860ece26cf5c Mon Sep 17 00:00:00 2001 From: Jerome Reybert <jreybert@gmail.com> Date: Fri, 30 Oct 2015 18:47:10 +0100 Subject: [PATCH] plugin/magit.vim: add mg_stage_closed_file function --- plugin/magit.vim | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/plugin/magit.vim b/plugin/magit.vim index e8a4ab0..4b78ead 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -646,6 +646,44 @@ function! magit#show_magit(display, ...) execute "normal! gg" endfunction +function! s:mg_stage_closed_file(discard) + if ( getline(".") =~ g:magit_file_re ) + let list = matchlist(getline("."), g:magit_file_re) + let filename = list[2] + let section=<SID>mg_get_section() + + let file = s:state.get_file(section, filename) + if ( file.is_visible() == 0 || + \ file.is_dir() == 1 ) + if ( a:discard == 0 ) + if ( section == 'unstaged' ) + call magit#git#git_add(magit#utils#add_quotes(filename)) + elseif ( section == 'staged' ) + call magit#git#git_reset(magit#utils#add_quotes(filename)) + else + echoerr "Must be in \"" . + \ g:magit_sections.staged . "\" or \"" . + \ g:magit_sections.unstaged . "\" section" + endif + else + if ( section == 'unstaged' ) + if ( file.must_be_added() ) + call delete(filename) + else + call magit#git#git_reset(filename) + endif + else + echoerr "Must be in \"" . + \ g:magit_sections.unstaged . "\" section" + endif + endif + call magit#update_buffer() + return + endif + endif + throw "out_of_block" +endfunction + function! s:mg_select_closed_file() if ( getline(".") =~ g:magit_file_re ) let list = matchlist(getline("."), g:magit_file_re) -- GitLab