git-worktree.nvim
git-worktree.nvim copied to clipboard
Feature: find bare root when creating worktrees
👋,
I'm using this plugin together with git clone --bare <repo> .git, which also in recommended in the README. When triggering Telescope git_worktree create_git_worktree it asks for a path to create the worktree in. If I input test as a path it will add the worktree in .git/test which I obviously do not want. The correct placement would be ../test here.
It would be really nice if was possible to configure git-worktree.nvim so it's able to find the bare root.
I run into the same problem will try to improve this
also have this problem, thanks for looking into it
I tested the code from #76 but there are some caveats with it: it only works if the bare root directory name doesn't end with .git and if it is the direct parent of the bare repository, which won't necessarily be true. (see bellow)
The problem is our bare repo (and non-bare repos too) could be anywhere really. It is popular (git default) when using non-bare repos to have the git repository under the same directory as the working tree but this isn't a requirement. When using bare repos we don't even have a working tree until we manually add it. We could change our bare git directory location using a .git file inside the bare root directory. If using a non-bare repo we could change change the git directory location using a .git file inside the working tree directory.
e.g.:
<foo>
└ .git
└ ...
- Inside
.gitfile (if using abarerepo)
gitdir: /home/myuser/git-repos/my-bare-repo
- If using a
non-barerepo:
gitdir: /home/myuser/git-repos/my-non-bare/.git
Currently when we change gitdir and use bare repos what happens is that git worktrees are created under gitdir instead of the bare root. When using non-bare repos they are created inside the previous directory from gitdir instead of the working tree directory.
We then have another problem: should we account for the use of git environment variables? We can change gitdir using $GIR_DIR and the working tree directory using $GIT_WORK_TREE (non-bare repos only). When using these variables we can have a quite unusual setup but for I what I've tested when using bare and non-bare repos the behavior is the same as the one described above.
I haven't deep dived into the code but those are some problems that I can think of. If I have time I'll try to come up with a solution for this.
@jvcarli wouldn't it be possible to have separate handling for both of these cases? If the user is in a non-bare repo then simply prompt to the user to setup a base-directory for that specific repository. if it is a bare repository then just keep working as it currently is.