From db72f829034a6090abc32afc3d01c1f4f5b8a62d Mon Sep 17 00:00:00 2001 From: Jerome Reybert <jreybert@gmail.com> Date: Thu, 8 Oct 2015 13:59:10 +0200 Subject: [PATCH] plugin/magit.vim: fix issue of some rare hunk staging (because of some whitespaces) --- plugin/magit.vim | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/plugin/magit.vim b/plugin/magit.vim index 28cb489..490d8e2 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -545,12 +545,17 @@ function! s:mg_git_apply(selection) if ( selection[-1] !~ '^\s*$' ) let selection += [ '' ] endif - silent let git_result=<SID>mg_system("git apply --cached -", selection) + " when passing List to system as input, there are some rare and + " difficultly reproductable cases failing because of whitespaces + let tmp=tempname() + call writefile(selection, tmp) + silent let git_result=<SID>mg_system("git apply --cached - < " . tmp) if ( v:shell_error != 0 ) echoerr "Git error: " . git_result echoerr "Tried to aply this" echoerr string(a:selection) endif + call delete(tmp) endfunction " s:mg_git_unapply: helper function to unstage a selection @@ -568,12 +573,17 @@ function! s:mg_git_unapply(selection, mode) if ( selection[-1] !~ '^\s*$' ) let selection += [ '' ] endif - silent let git_result=<SID>mg_system("git apply " . cached_flag . " --reverse - ", selection) + " when passing List to system as input, there are some rare and + " difficultly reproductable cases failing because of whitespaces + let tmp=tempname() + call writefile(selection, tmp) + silent let git_result=<SID>mg_system("git apply " . cached_flag . " --reverse - < " . tmp) if ( v:shell_error != 0 ) echoerr "Git error: " . git_result echoerr "Tried to unaply this" echoerr string(a:selection) endif + call delete(tmp) endfunction " s:mg_get_section: helper function to get the current section, according to -- GitLab