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

doesn't find the .git folder when starting vim from a subfolder #50

Closed ylmrx closed 4 years ago

ylmrx commented 4 years ago
git-messenger: Directory '/home/fuzzy/repos/mitmproxy/examples/addons' is not inside a Git repository

Can it try to search it in parent folders too instead of just $PWD ?

rafikdraoui commented 4 years ago

I think the problem is caused by this line:

https://github.com/rhysd/git-messenger.vim/blob/57848a3a9740f813f6305cc9a56342cd427c155e/autoload/gitmessenger/git.vim#L18

When file is empty, then fnamemodify(file, ':p') returns the full path of the cwd. This means that in some cases this can end up being wrongly set as dotgit instead of dir, which makes git-messenger fail with the "not in a git repo" error.

Changing the line to:

let file = empty(file) ? '' : fnamemodify(file, ':p')

fixes this for me, but I haven't verified if this still works for the submodules case (which I think is the reason why this was introduced). Maybe a similar check should be done for let dir = fnamemodify(dir, ':p') too.

ylmrx commented 4 years ago

I was working on another PR which just browse up till oblivion. But I’m fully new to vimscript , and I have no idea how to have the same behavior In Windows world. @rafikdraoui ‘s seems like a much better option.

francois-pasquier commented 4 years ago

@rhysd could you fix this? Could @rafikdraoui solution do the trick?

Great plugin btw!

rhysd commented 4 years ago

I'm sorry for the delay. I was fixing critical issue at github-action-benchmark and prioritized moving CI to GitHub Actions.

I'm not reproducing this issue, but @rafikdraoui's comment looks helpful. I'll try to fix this.

rhysd commented 4 years ago

@ylmrx @MeisterTea @rafikdraoui Since I'm not understanding how to reproduce this, would you check 422a933 fixed this issue?

rafikdraoui commented 4 years ago

I can confirm that https://github.com/rhysd/git-messenger.vim/commit/422a9334b9fe1dec9ecea6c0a1c48da71340e45f fixes this for me. Thanks!


Here's how I can reproduce the bug with commit d238582b28c (the one just before the fix). I don't have time to test with a minimal config (i.e. perhaps my vimrc or other plugins are interfering) or with vanilla vim, but maybe this could still be helpful:

$ git clone git@github.com:rhysd/git-messenger.vim.git
$ cd git-messenger.vim
$ nvim autoload/gitmessenger.vim

Then inside NeoVim:

:GitMessenger  " this works
:cd autoload
:GitMessenger  " this doesn't work
rhysd commented 4 years ago

@rafikdraoui Thank you for the detailed steps. It is very helpful for me. I also could confirm this issue was fixed by 422a933 on my local machine. I did not notice this issue because I usually set the current directory to a root of repository. I think I should add more test case to confirm relative paths work properly.

rhysd commented 4 years ago

Closing as I could confirm the fix.