zivyangll/git-blame.vim

`cd` error

Opened this issue · 12 comments

[Unhandled error: /usr/bin/cd: line 4: cd: $(dirname importNameRule.ts): No such file or directory]

vim info:
I am using vim-plugged

Plug 'zivyangll/git-blame.vim'
nnoremap <Leader>s :<C-u>call gitblame#echo()<CR>

VIM - Vi IMproved 8.1 (2018 May 18, compiled Feb 18 2019 23:51:40)
macOS version
Included patches: 1-950
Compiled by travis@Traviss-Mac.local
Huge version with MacVim GUI.  Features included (+) or not (-):
+acl               -farsi             +mouse_sgr         -tag_any_white
+arabic            +file_in_path      -mouse_sysmouse    -tcl
+autocmd           +find_in_path      +mouse_urxvt       +termguicolors
+autochdir         +float             +mouse_xterm       +terminal
-autoservername    +folding           +multi_byte        +terminfo
+balloon_eval      -footer            +multi_lang        +termresponse
+balloon_eval_term +fork()            -mzscheme          +textobjects
+browse            +fullscreen        +netbeans_intg     +textprop
++builtin_terms    -gettext           +num64             +timers
+byte_offset       -hangul_input      +odbeditor         +title
+channel           +iconv             +packages          +toolbar
+cindent           +insert_expand     +path_extra        +transparency
+clientserver      +job               +perl/dyn          +user_commands
+clipboard         +jumplist          +persistent_undo   +vartabs
+cmdline_compl     +keymap            +postscript        +vertsplit
+cmdline_hist      +lambda            +printer           +virtualedit
+cmdline_info      +langmap           +profile           +visual
+comments          +libcall           +python/dyn        +visualextra
+conceal           +linebreak         +python3/dyn       +viminfo
+cryptv            +lispindent        +quickfix          +vreplace
+cscope            +listcmds          +reltime           +wildignore
+cursorbind        +localmap          +rightleft         +wildmenu
+cursorshape       +lua/dyn           +ruby/dyn          +windows
+dialog_con_gui    +menu              +scrollbind        +writebackup
+diff              +mksession         +signs             -X11
+digraphs          +modify_fname      +smartindent       -xfontset
+dnd               +mouse             +startuptime       +xim
-ebcdic            +mouseshape        +statusline        -xpm
+emacs_tags        +mouse_dec         -sun_workshop      -xsmp
+eval              -mouse_gpm         +syntax            -xterm_clipboard
+ex_extra          -mouse_jsbterm     +tag_binary        -xterm_save
+extra_search      +mouse_netterm     +tag_old_static    
   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 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Linking: clang   -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib  -L/usr/local/lib -o Vim -framework Cocoa -framework Carbon       -lm  -lncurses -liconv -framework AppKit   -fstack-protector  -L/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE 

@dosentmatter can you provide more information?
system: linux/window?
and reproduce demo.

I am on macOS. I tried on an ubuntu docker image and seems to work fine. Here's what I tried in ubuntu docker container:

$ docker pull ubuntu
$ docker run --rm -it ubuntu bash
# apt update
# apt install vim git curl
# curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
# cat <<EOF > ~/.vimrc
call plug#begin('~/.vim/plugged')
Plug 'zivyangll/git-blame.vim'
nnoremap <Leader>s :<C-u>call gitblame#echo()<CR>
call plug#end()
EOF
# vim -c 'PlugInstall' -c 'qa'
# vim ~/.vim/plugged/git-blame.vim/autoload/gitblame.vim # <Leader>s works

On macOS, it doesn't work for me:

I went into vim debugger and it seems to be failing on this line.

  if a:0 == 0
    let output = s:has_vimproc() ?
          \ vimproc#system(command) : system(command)

I have vimproc installed so it is going into the first case. Note that I didn't have vimproc on ubuntu. The contents of the string is the following:

cd "$(dirname "/Users/kevinlau/.vim/plugged/git-blame.vim/autoload/gitblame.vim")"; git --no-pager blame "$(basename "/Users/kevinlau/.vim/plugged/git-blame.vim/autoload/gitblame.vim")" -L "$(basename "30")",+1 --porcelain

I saved the string to a global variable, let g:command = command and tried running the commands myself.

echo vimproc#system(g:command) fails just like in the plugin and I get:

/usr/bin/cd: line 4: cd: $(dirname /Users/kevinlau/.vim/plugged/git-blame.vim/autoload/gitblame.vim): No such file or directory
fatal: no such path '$(basename /Users/kevinlau/.vim/plugged/git-blame.vim/autoload/gitblame.vim)' in HEAD

vimproc seems to be failing on the initial cd cd "$(dirname "/Users/kevinlau/.vim/plugged/git-blame.vim/autoload/gitblame.vim")".
vimproc works with dirname "/Users/kevinlau/.vim/plugged/git-blame.vim/autoload/gitblame.vim". It seems to be failing on the $() command substitution. Not sure if vimproc supports that. If not, the code can be replaced with multiple calls to vimproc.
With a quick test, :echo vimproc#system('echo "$(echo 1)"') shows $(echo 1) and not 1.

echo system(g:command) doesn't fail and I get:

d06f5420467ada13f2f3ea0e75372bf1ef3181d1 30 30 1
author Charles Gueunet
author-mail <charles.gueunet@gmail.com>
author-time 1562210780
author-tz +0200
committer zivyangll
committer-mail <zivyangll@gmail.com>
committer-time 1562210780
committer-tz +0800
summary feat(neovim): use virtual text (#16)
boundary
filename autoload/gitblame.vim
	    let output = s:has_vimproc() ?

I tried with vimproc on ubuntu and it fails with other errors such as "cd" is not found. I don't think you should be using cd or command substitution. vimproc#system() docs says

Note: It does not execute a shell. So a shell internal command is invalid. Ex: pwd, cd, ...

The reason it works on macOS is because I have cd as a shell builtin and a binary:

$ type -a cd
cd is a shell builtin
cd is /usr/bin/cd

On ubuntu docker, it is only a builtin.

# type -a cd
cd is a shell builtin

So with vimproc#system(), you can't use any shell functionality such as command substitution, shell builtins, and semi-colons ; for multiple commands. If you want to execute a shell, you can pass the command to sh -c. For example, :echo vimproc#system('sh -c ' . "'cd; pwd'"). But then it won't work on windows. Doesn't look like you were supporting windows anyway since you are using shell syntax. Or maybe vimproc has another function where it does run in a shell.

docker pull ubuntu
docker run --rm -it ubuntu bash
# apt update
# apt install vim git curl make gcc
# curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
# cat <<EOF > ~/.vimrc
call plug#begin('~/.vim/plugged')
Plug 'zivyangll/git-blame.vim'
nnoremap <Leader>s :<C-u>call gitblame#echo()<CR>
Plug 'Shougo/vimproc.vim', {'do' : 'make'}
call plug#end()
EOF
# vim -c 'PlugInstall' -c 'qa'
# vim ~/.vim/plugged/git-blame.vim/autoload/gitblame.vim # <Leader>s works

very very details. I'm on MacOS same with you. and it's works. I tried with ubuntu docker, it's also works. Can you debugger with your MacOS, try to fix it? so that you can make a Pull Request?

Hmm do you also have vimproc installed?

I can try to take a look this weekend if I have time.

Same here.... using Linux and Vim 8,,,

[Unhandled error: fatal: no such path 'src/sp-shelter-point/edit-stay/sp-edit-particip
ating-clients.html' in HEAD]
vwal commented

Any update/progress on this? I also ran to this error on macOS.

I also ran to this error on Win10 and Vim8.

me too

me too

me too, ubuntu -> spacevim

before

if a:0 == 0
let output = s:has_vimproc() ?
\ vimproc#system(command) : system(command)

after it's ok

if a:0 == 0
let output = s:has_vimproc() ?
\ system(command) : vimproc#system(command)