You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When (neo)vim is used to open a tracked file from outside the git repository (e.g.: one directory above), vimagit manages to perform normal commits ('CC') correctly, however, when trying to amend a commit ('CA'), the previous commit message is not loaded.
Steps to reproduce
To reproduce the issue:
Setup a test repo typing the following commands:
$ cd ~
$ mkdir gitest
$ cd gitest
$ git init
$ mkdir sub
$ touch readme.txt
$ git commit -m 'initial commit'
get outside the repository and open "readme.txt"
$ cd ..
$ nvim readme.txt
from within (neo)vim:
:Magit
CA
Observe the issue
Expected result:
vimagit switches to amend mode and the previous commit message is shown in the 'Commit message' section.
Actual result:
vimagit switches to amend mode, but no text appears in the 'Commit message' section.
The cause seems to be that vimagit executes:
$ git rev-parse --git-dir
in the edited file directory which in this case is the top level of the repository, where the command returns a relative path to the .git directory, that is then stored in "b:magit_git_dir".
Later, when vimagit tries to open the file '.git/COMMIT_EDITMSG', the relative path will point to a non-existing file, since the editor's CWD is "gitest/.." instead of "gitest".
NOTE: opening the file from the top level dir of the repository as in:
$ cd $HOME/gitest
$ nvim readme.txt
would work.
NOTE: runnig the command:
$ git rev-parse --git-dir
in a subfolder of the repository:
$ mkdir sub
$ cd sub
$ git rev-parse --git-dir
would result in an absolute path.
Solution:
Since vimagit invokes
git rev-parse --git-dir
from the path of the edited file, using fnamemodify(git_dir, ':p') would solve the issue, since we are either in the top dir and the relative path is correctly turned to an absolute one, or we are in a subdir and the path is already absolute.
I am currently reviving the project, more specifically the CI, which has not been run/updated since github abandoned travis.
I plan to finish this next week.
Your issue seems to be a valid case to be fixed, but it touches fundamental vimagit operations, so I prefer to ensure your fix passes the testsuite.
Short description
When (neo)vim is used to open a tracked file from outside the git repository (e.g.: one directory above), vimagit manages to perform normal commits ('CC') correctly, however, when trying to amend a commit ('CA'), the previous commit message is not loaded.
Steps to reproduce
To reproduce the issue:
Setup a test repo typing the following commands:
$ cd ~
$ mkdir gitest
$ cd gitest
$ git init
$ mkdir sub
$ touch readme.txt
$ git commit -m 'initial commit'
get outside the repository and open "readme.txt"
$ cd ..
$ nvim readme.txt
from within (neo)vim:
:Magit
CA
Observe the issue
Expected result:
vimagit switches to amend mode and the previous commit message is shown in the 'Commit message' section.
Actual result:
vimagit switches to amend mode, but no text appears in the 'Commit message' section.
The cause seems to be that vimagit executes:
$ git rev-parse --git-dir
in the edited file directory which in this case is the top level of the repository, where the command returns a relative path to the .git directory, that is then stored in "b:magit_git_dir".
Later, when vimagit tries to open the file '.git/COMMIT_EDITMSG', the relative path will point to a non-existing file, since the editor's CWD is "gitest/.." instead of "gitest".
NOTE: opening the file from the top level dir of the repository as in:
$ cd $HOME/gitest
$ nvim readme.txt
would work.
NOTE: runnig the command:
$ git rev-parse --git-dir
in a subfolder of the repository:
$ mkdir sub
$ cd sub
$ git rev-parse --git-dir
would result in an absolute path.
Solution:
Since vimagit invokes
git rev-parse --git-dir
from the path of the edited file, using fnamemodify(git_dir, ':p') would solve the issue, since we are either in the top dir and the relative path is correctly turned to an absolute one, or we are in a subdir and the path is already absolute.
Environment
neovim version:
NVIM v0.7.2
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by team+vim@tracker.debian.org
git version 2.35.1
current vimagit: 88720f4
OS: Linux 5.18.0-2-amd64 # 1 SMP PREEMPT_DYNAMIC Debian 5.18.5-1 (2022-06-16) x86_64 GNU/Linux
both terminal nvim and nvim-qt are affected
The text was updated successfully, but these errors were encountered: