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

Error when in submodule #49

Closed bo5o closed 4 years ago

bo5o commented 4 years ago

When I try to call git-messenger in a submodule it fails with an error like:

git-messenger: fatal: no such path 'path/to/submodule/path/to/file' ... exited with non-zero status 128

To explain a little more:

path/to/submodule is the path to the sub module from the top-level repository (containing .git). path/to/file is the path to the file from where I am calling git-messenger relative to submodule directory.

I am using vim-rooter to automatically change into project root directories identified by .git directory/file, Now, submodules are special, because they also contain a .git file, but this is just a text file containing the path to the submodule git directory like this:

gitdir: relative/path/to/toplevel_repo/.git/modules/path/to/submodule

vim-rooter behaves correctly by changing into path/to/submodule which is what I want most of the time. So when I open a file inside the submodule vim automatically changes into the directory of the submodule. Git-messenger however resolves the path up until the top-level repo and of course, the path/to/submodule/path/to/file doesn't exist relative to the current submodule directory, giving the above error.

I think a fix for correctly finding .git was introduced for git worktrees in this commit. Maybe this can be extended to also handle submodules.

rhysd commented 4 years ago

As far as I tried with my repository, it works fine.

rhysd commented 4 years ago

OK, I could reproduce with my repository when trying various paths in the repository. This issue occurs in specific situation related to location of .git file/directory and target file. The difference of finddir and findfile causes this issue.

rhysd commented 4 years ago

@cbows I fixed this issue at 57848a3. At least I confirmed the issue which I saw in my local was fixed. Please update this plugin to the latest and check this issue was solved.

bo5o commented 4 years ago

Sorry, I will provide more information.

git-messenger version

I'm on the latest commit 6282cae

:version

NVIM v0.4.2
Build type: RelWithDebInfo
LuaJIT 2.0.5
Compilation: /usr/bin/gcc-5 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -g -DMIN_LOG_LEVEL=3 -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/home/travis/build/neovim/bot-ci/build/neovim/build/config -I/home/travis/build/neovim/bot-ci/build/neovim/src -I/home/travis/build/neovim/bot-ci/build/neovim/.deps/usr/include -I/usr/include -I/home/travis/build/neovim/bot-ci/build/neovim/build/src/nvim/auto -I/home/travis/build/neovim/bot-ci/build/neovim/build/include
Übersetzt von travis@travis-job-f793f209-fee5-4ecb-af65-2814cc327d55

Features: +acl +iconv +tui
See ":help feature-compile"

          System-vimrc-Datei: "$VIM/sysinit.vim"
     Voreinstellung für $VIM: "/home/travis/build/neovim/bot-ci/build/neovim/build/nvim.AppDir/usr/share/nvim"

:checkhealth

health#gitmessenger#check
=====================
  - OK: +job is available to execute Git command
  - OK: Git command `git` is available: git version 2.17.1
  - OK: Floating window is available for popup window

I am sorry for mentioning vim-rooter, the same effect can be achieved by using :cd path/to/submodule.

I tried to be general with the path descriptions in my example, in case of your repository, path/to/submodule would be monolith and path/to/file would be, e.g. LICENSE, which is inside submodule. So calling git-messenger when editing LICENSE produces the error I described.

I tried with your repository. When I cd into the submodule I get the same error:

git-messenger: fatal: no such path 'monolith/LICENSE' in HEAD : `git --no-pager blame /<...>/monolith-of-web/monolith/LICENSE -L 1,+1 --porcelain` exited with non-zero status 128
bo5o commented 4 years ago

@cbows I fixed this issue at 57848a3. At least I confirmed the issue which I saw in my local was fixed. Please update this plugin to the latest and check this issue was solved.

Your very fast. Issue fixed in your example repository as well as in mine.