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

Does not detect symlinks #68

Closed anihm136 closed 3 years ago

anihm136 commented 3 years ago

Hi! I've been using this plugin for a few months now, and today I noticed that it does not detect a symlinked folder that is inside a git directory. That is, if the original directory/file is in a git repo, and I am accessing the symlink through vim, it does not detect the repo. WOuld it be possible to add this enhancement?

rhysd commented 3 years ago

Would you make a repro? Do you mean following situation?

mkdir foo && cd foo
mkdir bar && cd bar && git init .
touch a && git add a && git commit -m test
cd ..
ln -s b ./foo/a
vim b
anihm136 commented 3 years ago

Okay, sorry to file without exploring fully. The minimal case works fine. Here is the specific case that I'm having issues with - Directory structure is as follows -

A.txt -> symlink to a file in a repo
B/ -> symlink to a directory in a repo
    C.txt -> file inside B (inside the repo) 

Now, it works fine when

  1. I open C.txt as nvim B/C.txt
  2. cd B && nvim ../A.txt However, the following cases don't work -
  3. nvim A.txt - does not detect A.txt as a version controlled file
  4. After opening A.txt. :edit B/C.txt - does not detect C.txt as a version controlled file This is probably a very niche case, and maybe not recommended by git itself (this is basically how I have all my dotfiles set up). Let me know if I can share any more info
anihm136 commented 3 years ago

Also worth noting that I am using neovim, not vim

rhysd commented 3 years ago

This is not an issue because symlinks outside repository are not handled as files in the repository by Git.

$ mkdir foo && cd foo
$ git init .
$ touch A
$ cd ..
$ ln -s ./foo/A B
$ git add B
fatal: not a git repository (or any of the parent directories): .git

Symlink is not resolved automatically. The linked file is treated as if it is put in the same directory where the symlink is put in. This behavior seems standard in many other CLI tools; they don't resolve symlinks. git-messenger.vim also should follow this behavior, I think.