Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: find bare root when creating worktrees #73

Open
sQVe opened this issue Dec 16, 2021 · 4 comments
Open

Feature: find bare root when creating worktrees #73

sQVe opened this issue Dec 16, 2021 · 4 comments

Comments

@sQVe
Copy link

sQVe commented Dec 16, 2021

👋,

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.

@sQVe sQVe changed the title Feature: find bare root when creating worktree Feature: find bare root when creating worktrees Dec 16, 2021
@polarmutex
Copy link
Collaborator

I run into the same problem will try to improve this

@punk-dev-robot
Copy link

also have this problem, thanks for looking into it

@jvcarli
Copy link

jvcarli commented Mar 17, 2022

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 .git file (if using a bare repo)
gitdir: /home/myuser/git-repos/my-bare-repo

  • If using a non-bare repo:
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.

@Chaitanyabsprip
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants