From 260182c65cae653ac20e6a69ba8cc6124e7ba6c2 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Thu, 30 Jul 2020 21:36:29 -0400 Subject: [PATCH] Support partial staging after git add -N Closes https://github.com/tpope/vim-fugitive/issues/1567 --- autoload/fugitive.vim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 42b8291..231ea7f 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -3521,7 +3521,12 @@ function! s:StageApply(info, reverse, extra) abort let i = b:fugitive_expanded[info.section][info.filename][0] let head = [] while get(b:fugitive_diff[info.section], i, '@') !~# '^@' - call add(head, b:fugitive_diff[info.section][i]) + let line = b:fugitive_diff[info.section][i] + if line ==# '--- /dev/null' + call add(head, '--- ' . get(b:fugitive_diff[info.section], i + 1, '')[4:-1]) + elseif line !~# '^new file ' + call add(head, line) + endif let i += 1 endwhile call extend(lines, head, 'keep') @@ -3731,7 +3736,7 @@ function! s:DoUnstageStaged(record) abort endfunction function! s:DoToggleUnstaged(record) abort - if a:record.patch && a:record.status !=# 'A' + if a:record.patch return s:StageApply(a:record, 0, ['--cached']) else call s:TreeChomp(['add', '-A', '--'] + a:record.paths)