Closed syurazo closed 4 years ago
% cd /PATH/TO/agit.vim
agit.vim[master]%
agit.vim[master]% vim README.md -c 'echo b:git_dir'
:
:
"README.md" 42L, 847C
/PATH/TO/agit.vim/.git
when b:git_dir
is "/PATH/TO/agit.vim/.git", s:get_git_root()
returns "/PATH/TO/agit.vim" as expected
% cd /PATH/TO/agit.vim
agit.vim[master]%
agit.vim[master]% git worktree add .worktree/fix_agitfile_error fix_agitfile_error
agit.vim[master]% cd .worktree/fix_agitfile_error/
agit.vim[fix_agitfile_error]% vim README.md -c 'echo b:git_dir'
:
:
"README.md" 42L, 847C
/PATH/TO/agit.vim/.git/worktrees/fix_agitfile_error
when b:git_dir
is "/PATH/TO/agit.vim/.git/worktrees/fix_agitfile_error", GITROOT expected "/PATH/TO/agit.vim/.wotktree/wfix_agitfile_error", but actually s:get_git_root()
returns "/PATH/TO/agit.vim".
This error is caused by git worktree
command, right?
I should have consulted on Issues in advance...
This error is caused by git worktree command, right?
AgitFile
will show an error only worktrees that have created by git worktree add
.
The .git
file of the worktree created by git worktree add
is the same as the case where the working tree was separated using --separate-git-dir
. #48
The .git
file contains the PATH of the.git
directory in the repository. The b:git_dir
referenced when fugitive
is enabled seems to be the same as gitdir:
in the .git
file. s:get_git_root()
returns the PATH excluding .git.*
command | b:git_dir |
matchstr(b:git_dir, '^.\+\ze\.git') |
---|---|---|
git clone ...agit.vim |
.../agit.vim/.git |
.../agit.vim/ |
git clone --separate-gir-dir <PATH> ...agit.vim |
PATH |
PATH/ |
git add wotktree <WTPATH> <BRANCH> |
.../agit.vim/.git/wotktree/BRANCH |
.../agit.vim/ |
agit#git#exec()
is running git -C
, so I expected to see the above <WTPATH>
, but it actually points to the original repository.
tmp% git clone https://github.com/cohama/agit.vim.git
tmp% cd agit.vim/
agit.vim[master]% git branch feature
agit.vim[master]% git worktree add .feature feature
agit.vim[master]% cd .feature
.feature[feature]% cat .git
gitdir: /tmp/agit.vim/.git/worktrees/-feature
.feature[feature]% git -C /tmp/agit.vim/.git/worktrees/-feature ls-files /tmp/agit.vim/.feature/README.md // NG
fatal: /tmp/agit.vim/.feature/README.md: '/tmp/agit.vim/.feature/README.md' is outside repository
.feature[feature]% git -C /tmp/agit.vim ls-files /tmp/agit.vim/.feature/README.md // NG
.feature[feature]% git -C /tmp/agit.vim/.feature ls-files /tmp/agit.vim/.feature/README.md // OK
README.md
Make sense. Thank you for your contribution!
If fugitive is available,
s:get_git_root()
returns path with .git removed from GitDir. That path is passed to thegit -C
option, but-C
must specify the ROOT PATH where.git
resides, not GitDir.Use
FugitiveWorkTree()
instead ofb:git_dir
Fugitive's variable.FugitiveWorkTree()
seems to return the intended GIT ROOT even in directories checked out bygit worktree add