airblade / vim-gitgutter

A Vim plugin which shows git diff markers in the sign column and stages/previews/undoes hunks and partial hunks.
MIT License
8.38k stars 297 forks source link

GitGutterQuickFix does not work #822

Closed DehanLUO closed 2 years ago

DehanLUO commented 2 years ago

Nothing was added to my QuickFix list after I did some change and executed :w<CR>:GitGutterQuickFix\|copen<CR>.

logs channel.log gitgutter.log

screenshot Snipaste_2022-03-17_23-43-34

What is the latest commit SHA in your installed vim-gitgutter? 18d12985ea6cb7ede59755ff4fd0a9fa1e6bf835 What vim/nvim version are you on?

:version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Sep 24 2021 14:13:28)
macOS version - x86_64
Included patches: 1-3455
Compiled by GitHub Actions
Huge version with MacVim GUI.  Features included (+) or not (-):
+acl               +cursorshape       +ipv6              -mouse_sysmouse    +ruby/dyn          +title
+arabic            +dialog_con_gui    +job               +mouse_urxvt       +scrollbind        +toolbar
+autocmd           +diff              +jumplist          +mouse_xterm       +signs             +transparency
+autochdir         +digraphs          +keymap            +multi_byte        +smartindent       +user_commands
-autoservername    +dnd               +lambda            +multi_lang        -sodium            +vartabs
+balloon_eval      -ebcdic            +langmap           -mzscheme          -sound             +vertsplit
+balloon_eval_term +emacs_tags        +libcall           +netbeans_intg     +spell             +virtualedit
+browse            +eval              +linebreak         +num64             +startuptime       +visual
++builtin_terms    +ex_extra          +lispindent        +odbeditor         +statusline        +visualextra
+byte_offset       +extra_search      +listcmds          +packages          -sun_workshop      +viminfo
+channel           -farsi             +localmap          +path_extra        +syntax            +vreplace
+cindent           +file_in_path      +lua/dyn           +perl/dyn          +tag_binary        +wildignore
+clientserver      +find_in_path      +menu              +persistent_undo   -tag_old_static    +wildmenu
+clipboard         +float             +mksession         +popupwin          -tag_any_white     +windows
+cmdline_compl     +folding           +modify_fname      +postscript        -tcl               +writebackup
+cmdline_hist      -footer            +mouse             +printer           +termguicolors     -X11
+cmdline_info      +fork()            +mouseshape        +profile           +terminal          -xfontset
+comments          +fullscreen        +mouse_dec         +python/dyn        +terminfo          +xim
+conceal           +gettext           -mouse_gpm         +python3/dyn       +termresponse      -xpm
+cryptv            -hangul_input      -mouse_jsbterm     +quickfix          +textobjects       -xsmp
+cscope            +iconv             +mouse_netterm     +reltime           +textprop          -xterm_clipboard
+cursorbind        +insert_expand     +mouse_sgr         +rightleft         +timers            -xterm_save
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
system gvimrc file: "$VIM/gvimrc"
user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
defaults file: "$VIMRUNTIME/defaults.vim"
system menu file: "$VIMRUNTIME/menu.vim"
fall-back for $VIM: "/Applications/MacVim.app/Contents/Resources/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_MACVIM -Wall -Wno-unknown-pragmas -pipe -DMACOS_X -DMACOS_X_
DARWIN -g -O2 -arch x86_64 -arch arm64 -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -Wall -Wextra -Wshadow -Werror
-Wno-error=missing-field-initializers -Wno-error=deprecated-declarations -Wno-error=unused-function
Linking: clang -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl@1.1/li
b -L/usr/local/opt/readline/lib -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/o
pt/openssl@1.1/lib -L/usr/local/opt/readline/lib -arch x86_64 -arch arm64 -L/usr/local/lib -o Vim -lm -lncurses -liconv /
usr/local/lib/libintl.a -framework AppKit -fstack-protector -L/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE 

and my vimrc


" Set fonts for gVim
if has('win32')&&has('gui_running')
set gfn=Hack_Nerd_Font_Mono:h11:cANSI:qDRAFT
elsei has('gui_running')&&has('gui_macvim')
set gfn=Hack\ Nerd\ Font\ Mono:h12
en

" Plugins settings " Automatic installation of missing plugins " @https://github.com/junegunn/vim-plug/wiki/tips#automatic-installation " Download vim-plug if plug.vim not found if has('unix') " For unix system " Install vim-plug if not found if empty(glob('~/.vim/autoload/plug.vim')) sil !curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim en elsei has('win32') "For windows system if empty(glob('$HOME/vimfiles/autoload/plug.vim')) sil !curl -fLo \%HOMEPATH\%/vimfiles/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim en en

" Run PlugInstall if there are missing plugins au VimEnter * if len(filter(values(g:plugs), '!isdirectory(v:val.dir)')) | PlugInstall --sync | so $MYVIMRC | en

" Plugins package manager if has('unix') cal plug#begin('~/.vim/plugged') elsei has('win32') cal plug#begin('$HOME/vimfiles/plugged') en

Plug 'vim-airline/vim-airline' " Lean and mean statusline
Plug 'airblade/vim-gitgutter' " Show git status

cal plug#end()

" PlugCfg 'airblade/vim-gitgutter' :help gitgutter.txt let g:gitgutter_log=1 let g:gitgutter_map_keys=0 " Clear all gitgutter mappings

set scl=yes " Always draw the signcolumn let g:gitgutter_signs=1 " Show signs " Customise the symbols let g:gitgutter_sign_added='' let g:gitgutter_sign_modified='שׂ' let g:gitgutter_sign_modified_removed='' let g:gitgutter_sign_removed='' let g:gitgutter_sign_removed_above_and_below='' let g:gitgutter_sign_removed_first_line='' " Sync LineNr background color hi! link SignColumn LineNr hi! link GitGutterAdd LineNr hi! link GitGutterChange LineNr hi! link GitGutterDelete LineNr hi! link GitGUtterChangeDelete LineNr " Give the foreground color to GitGutter_Sign hi GitGutterAdd guifg=#009900 ctermfg=Green hi GitGutterChange guifg=#bbbb00 ctermfg=Yellow hi GitGutterDelete guifg=#ff2222 ctermfg=Red hi GitGUtterChangeDelete guifg=#ff2222 ctermfg=Red

if has('gui_running') let g:gitgutter_highlight_lines=1 " Enable line highlighting

" Give the background color to GitGutter_Line
hi GitGutterAddline guibg=#013220 ctermbg=NONE
hi GitGutterChangeline guibg=#53480d ctermbg=NONE
hi GitGutterDeleteline guibg=#430805 ctermbg=NONE

en

" Get a list of counts of added, modified, and removed lines let g:airline#extensions#hunks#enabled=1 " Showing a summary of changed hunks let g:airline#extensions#hunks#non_zero_only=0 " Showing all hunks let g:airline#extensions#hunks#hunk_symbols=['','שׂ',''] " Set count symbols

" Augment folded text with an indicator of weather lines have been changed set fdt=gitgutter#fold#foldtext()

"Stage/undo/preview the hunk nm hs :GitGutterStageHunk nm hu :GitGutterUndoHunk nm hp :GitGutterPreviewHunk

" Fold/execute unchanged lines nm gf :GitGutterFold

let g:gitgutter_use_location_list=0 " Hunks not to the location list " Load all SAVED hunks into window's/quickfix list com! Gqf GitGutterQuickFix |cope nm gqf :Gqf

nmap gqf :w:GitGutterQuickFix|copen

" Next/Previous hunk cycle through hunks in current buffer nm gj :call GitGutterNextHunkCycle() nm gk :call GitGutterPrevHunkCycle() fu! GitGutterNextHunkCycle() let line = line('.') sil! GitGutterNextHunk if line('.') == line 1 GitGutterNextHunk en endf fu! GitGutterPrevHunkCycle() let line = line('.') sil! GitGutterPrevHunk if line('.') == line norm! G GitGutterPrevHunk en endf

airblade commented 2 years ago

Thanks for the detailed report. However I can't reproduce the problem.

When I type this:

:nmap <Leader>gqf :w<CR>:GitGutterQuickFix\|copen<CR>

– and then in normal mode type \gqf (my leader key is \), it works: it saves the buffer, loads the diff locations into the quickfix list, and opens it.

Does the GitGutterQuickFix command work when you execute it directly? I.e. when you do this:

:w
:GitGutterQuickFix
:copen

By the way you don't need let g:gitgutter_signs=1 because that's the default anyway.

DehanLUO commented 2 years ago

Thanks, Nothing was output after executing GitGutterQuickFix directly. Snipaste_2022-03-18_05-12-45

DehanLUO commented 2 years ago

Thanks so much. I've found the key. After I set vim log to verbose, I found the GitGutterQuickFix did the following command in a child process.

(git  --no-pager diff --no-ext-diff --no-color -U0 --src-prefix=a/ --dst-prefix=b/  )>/var/folders/_d/bsqrml45219_br128q2pgsg40000gn/T/v03Ac2B/6 2>&1

This works for the gVim(MacVim) launched from command line interface.

However, I installed my MacVim via homebrew.

brew install macvim --cask

If I launched MacVim from the launchpad icon. This causes problem. Snipaste_2022-03-18_05-45-14

airblade commented 2 years ago

Well spotted.

GitGutterQuickFix uses systemlist() to run the diff so I think this must be a bug in MacVim

DehanLUO commented 2 years ago

Here is the problem when I run GitGutterQuickFix with gVim launched from launchpad

image

And this is what I got when I launched gVim from CLI

image
DehanLUO commented 2 years ago

The key is that if I run :echo systemlist('pwd') when I open my vimrc in both gvim, I got different Print Working Directory. With CLI : ['/Users/dehan/.vim'] With Launchpad: ['/Users/dehan']

Seems that adding an absolute path to the git command can sovle the problem?

airblade commented 2 years ago

The first thing GitGutterQuickFix does is establish the path to the repo – that's the git rev-parse --show-cdup. It assumes your current working directory is somewhere within your repo. Your first screenshot suggests that your current working directory is not in your repo. What does :pwd produce in gVim launched from launchpad?

The second screenshot shows an error unrelated to the plugin. Your vim is having trouble setting up the quickfix window because it can't find an indent file.

airblade commented 2 years ago

Seems that adding an absolute path to the git command can sovle the problem?

Then the quickfix window will be much harder to read, with long absolute paths in the filenames.

What does :pwd inside Vim give?

DehanLUO commented 2 years ago

Seems it is fixed to where I launched my gVim.

Even if I launched gvim in CLI at $HOME and executed :e $MYVIMRC, :pwd and echo systemlist('pwd') still gave the path where I launched from. /Users/dehan

airblade commented 2 years ago

I use vim-rooter to make sure my working directory is always the repo I'm working in.

DehanLUO commented 2 years ago

I use vim-rooter to make sure my working directory is always the repo I'm working in.

Thank you again for all your information and assistance. I should have a try. Have a Great Day.

airblade commented 2 years ago

You too!