From 5dcf8a01756f30b8a6fae07c8db5580e8ce69af5 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 10 Jul 2015 12:39:36 +0200 Subject: [PATCH] ReplaceCmd: redirect stderr to tmp file / buffer The option `status.showUntrackedFiles=all` used with `git status` for `:Gstatus` might cause an error, which then causes fugitive to display an empty status window / index file. Redirecting the stderr output is useful in this case. The generated command was: git --git-dir=/home/user/.dotfiles/.git -c 'status.displayCommentPrefix=true' -c 'color.status=false' -c 'status.short=false' -c 'status.showUntrackedFiles=all' status The error from git is related to submodules being moved to another subdirectory, where the relative "gitdir" now does not exist anymore: fatal: Not a git repository: vim/bundle.old.nobackup/CLEAN/colorscheme-base16/../../../.git/modules/vim/bundle/colorscheme-base16 While that's a Git / user error after all, fugitive should be more helpful in that case by displaying the error. It uses the 'shellpipe' setting to detect if '2>&1' is supported (Ref: https://github.com/tpope/vim-fugitive/pull/661#issuecomment-120438667). Closes #661. --- plugin/fugitive.vim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index 0543582..cd7e560 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -2398,11 +2398,15 @@ function! s:ReplaceCmd(cmd,...) abort let prefix = 'env GIT_INDEX_FILE='.s:shellesc(a:1).' ' endif endif + let redir = ' > '.tmp + if &shellpipe =~ '2>&1' + let redir .= ' 2>&1' + endif if s:winshell() let cmd_escape_char = &shellxquote == '(' ? '^' : '^^^' - call system('cmd /c "'.prefix.s:gsub(a:cmd,'[<>]', cmd_escape_char.'&').' > '.tmp.'"') + call system('cmd /c "'.prefix.s:gsub(a:cmd,'[<>]', cmd_escape_char.'&').redir.'"') else - call system(' ('.prefix.a:cmd.' > '.tmp.') ') + call system(' ('.prefix.a:cmd.redir.') ') endif finally if exists('old_index')