git-blame.vim icon indicating copy to clipboard operation
git-blame.vim copied to clipboard

Added symlink support

Open Kadiryanik opened this issue 3 years ago • 3 comments

If there is a symlink pointing to a file in the same directory, vim uses it as the filename.

Kadiryanik avatar Feb 09 '22 20:02 Kadiryanik

@Kadiryanik what does this actually do...?

mralusw avatar Jan 28 '24 09:01 mralusw

If we create a symlink in the same directory, the blame was trying to read that symlink file changes.

You can try it as below.

  1. Create the testfile in a git repo.
  2. Put some lines in it.
  3. Create a symlink to that file in the same dir.
  4. Commit all changes.
  5. Open symlink to edit in vim.
  6. Try to get blame result (except first line) with this plugin.
  7. You will get the error: [Unhandled error: fatal: file symlink-to-testfile has only 1 line]

If you apply this patch and check the step 5 & 6, you will get exact blame result. This patch aims to get exact file name from symlink and run git blame on it.

Please let me know if this is still not clear.

Kadiryanik avatar Feb 22 '24 09:02 Kadiryanik

Ah. So you're following history through the symlink. And you probably want realpath (readlink itself might return a link). There is no need for basename as git can resolve full paths to repo-relative paths.

I've merged your commit (and the popup PR) into my fork, https://github.com/kstr0k/git-blame.vim/ (it seems the original repo here might not be getting updates at this point).

For reference, vim has %:p:h expansion (no need for dirname) and git has -C dir (no need for separate cd ...; git ...).

There was also a $(basename) applied to the line number, which seemed superfluous, but maybe I'm missing some neovim thing.

mralusw avatar Feb 23 '24 09:02 mralusw