rhysd / git-messenger.vim

Vim and Neovim plugin to reveal the commit messages under the cursor
MIT License
1.34k stars 32 forks source link

Outside repository error on windows with msys/git #57

Open hokorobi opened 4 years ago

hokorobi commented 4 years ago

Giving a full path to msys/git doesn't seem to work well. When :GitMesseger is executed on the C:\Users\hokorobi\vimfiles\vimrc, it will be as follows.

git-messenger: fatal: 'C:\Users\hokorobi\vimfiles\vimrc' is outside repository at '/home/hokorobi/vimfiles': `git --no-pager blame C:\Users\hokorobi\vimfiles\vimrc -L 1,+1 --porcelain` exited with non-zero status 128
rhysd commented 4 years ago
  1. Would you try exactly the same command from command line directly and confirm you can get the same error? It is weird that git -C is not used. My assumption is that git-messenger.vim is always using git -C {dir} to run Git commands in specific directory. It may not be working.
  2. If you have installed Git for Windows, would you also try its git command by setting g:git_messenger_git_command?
hokorobi commented 4 years ago
  1. I get the same error on the command line.

    C:\Users\hokorobi\vimfiles>git --no-pager blame C:\Users\hokorobi\vimfiles\vimrc -L 1,+1 --porcelain
    fatal: 'C:\Users\hokorobi\vimfiles\vimrc' is outside repository at '/home/hokorobi/vimfiles'

    It seems that msys git expects a UNIX-like path. It's not an error this. C:\Users\hokorobi\vimfiles>git --no-pager blame /home/hokorobi/vimfiles/vimrc -L 1,+1 --porcelain

  2. I haven't installed Git for Windows, so I can't try it, but I've heard that VSCode Git doesn't cause an error.

rhysd commented 4 years ago

Thank you for the investigation. Regarding to 1., this command is not what I expected. My expectation was:

git --no-pager -C C:\Users\hokorobi\vimfiles blame C:\Users\hokorobi\vimfiles\vimrc -L 1,+1 --porcelain

Would you ensure above command also does not work?

It seems that msys git expects a UNIX-like path

It looks root cause of this issue. I'm not user of MSYS so not familiar with it. Would you answer below questions if you know the answer?

rhysd commented 4 years ago

Since using relative path is problematic, I want to solve this issue by converting Windows path to Unix-like path when running git command.

hokorobi commented 4 years ago
  1. It was the same result.
    C:\Users\hokorobi\vimfiles>git --no-pager -C C:\Users\hokorobi\vimfiles blame C:\Users\hokorobi\vimfiles\vimrc -L 1,+1 --porcelain
    fatal: 'C:\Users\hokorobi\vimfiles\vimrc' is outside repository at '/home/hokorobi/vimfiles'

how can we detect MSYS git? (for example, from path of git command)

$PATH has a path with git in it.

is there any utility which converts Windows file path to MSYS's unix-like path? For example, cygwin has cygpath utility command

I will investigate.

hokorobi commented 4 years ago

MSYS also has cygpath.

hokorobi commented 4 years ago

Git for Windows works fine. It may be good to say that it doesn't work in MSYS Git.

rhysd commented 4 years ago

Thank you for the investigation. It is very helpful.

$PATH has a path with git in it.

I apologize that my question was bad. My intention was that I wanted to detect git command which was installed with MSYS. Hence we can convert Windows path to Unix-like path only when the git command is installed via MSYS.

If git is installed in MSYS-specific directory (e.g. including 'msys' in its path), we can detect it by return value from exepath().

MSYS also has cygpath.

Thank you. My understanding is that the path converted by cygpath is used for MSYS Git, though I'm not sure this is correct.

It may be good to say that it doesn't work in MSYS Git.

At least for now, it should be noted. Thank you for suggestion. I'll add note to README.

hokorobi commented 4 years ago

Thank you for writing the document. You may also close this issue.

rhysd commented 4 years ago

I'll keep this issue open because this issue is not solved.