-
-
Notifications
You must be signed in to change notification settings - Fork 18
Enable upstream tracking #32
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
Conversation
Currently, the user experience when creating worktrees that track remote upstreams are not straight forward. This patch improves it by allowing the user to pass any ref to the --track option of git.
This is especially useful when creating or deleting a worktree, to avoid deleting errors if the user is within the to-be deleted worktree or unintended nested paths when creating.
Follow the same naming convention of the main picker.
This means that a user can create a worktree when there is none, so allow for an empty worktree list by not returning early if #results == 0.
Other pickers already use <c-d> for scrolling preview and telescope-file-browser.nvim use <m-d> for deleting files, so use that for consistency.
This corrects the output and make unnecessary to make use of :gsub and :trim.
Currently, if the user chooses a remote branch to checkout, it will be created locally with the same name causing it to produce an ambiguous ref which git won't be able to use as upstream to track. This defaults the new local branch to be prefixed with "local/".
a8e7c38 to
657538f
Compare
657538f to
0f6da26
Compare
|
I will look at this soon |
|
@rbmarliere ; thanks for taking a stab at implementing this; I've been sorely wanting this functionality as of late :)
|
Thanks for the review! As a disclaimer I'm not very knowledgeable with Lua and plugins in general and it was indeed mostly a hack with lots of trial and error... But it somewhat worked for me and thus decided to share upstream.
The problem I faced was wanting to create a branch named "foo" but that string still yielded results like "remote1/foo" so I needed another action (mapped to tab) that would create it anyway. Could be better indeed. But the lines you linked has to do with the branch to create, not track. Tracking comes later.
If I understood correctly, you'd be trying to create a tree in path "tree2" checking out a branch already in use in "tree1", if so then it fails silently due to: 16:39:56 rbmarliere@opensuse /mnt/ext/src/rbmarliere/git-worktree.nvim BARE:main
$ git worktree list
/mnt/ext/src/rbmarliere/git-worktree.nvim (bare)
/mnt/ext/src/rbmarliere/git-worktree.nvim/devel edd16a7da828 [devel]
/mnt/ext/src/rbmarliere/git-worktree.nvim/main bac72c240b6b [main]
16:40:13 rbmarliere@opensuse /mnt/ext/src/rbmarliere/git-worktree.nvim BARE:main
$ git worktree add devel2 devel
Preparing worktree (checking out 'devel')
fatal: 'devel' is already used by worktree at '/mnt/ext/src/rbmarliere/git-worktree.nvim/devel'
The reason behind this is to avoid errors when the user deletes the currently selected tree and avoid nested paths when creating a new tree while being "within" (selected) a tree already. That way the path is always relative to the bare repo basedir.
That's a fair point.
I wasn't happy with this one either. The problem is, when creating and being presented the branches list to choose, you might either create a new one or select a remote branch. If you select a remote branch, this is what would happen: $ git worktree add rbmarliere/track_upstream -b rbmarliere/track_upstream --track rbmarliere/track_upstream
Preparing worktree (new branch 'rbmarliere/track_upstream')
branch 'rbmarliere/track_upstream' set up to track 'rbmarliere/track_upstream'.
warning: refname 'rbmarliere/track_upstream' is ambiguous.
HEAD is now at 0f6da2603450 feat: Enable user to create detached worktreeBut instead, this is what happens: $ git worktree add rbmarliere/track_upstream -b local/rbmarliere/track_upstream --track rbmarliere/track_upstreamIt works for me but I agree it's not optimal. Another option would be to limit the branch list to local/remote and split the functionalities. So, one action for each. But that's not great either. I'm very interested in suggestions here.
Good point. I did it just to get over with and avoid more refactoring... :)
I didn't follow this point. You need to pass a valid ref to in --track. Please do share your thoughts! We can always improve things. There's a couple of bugs that I've been hitting but still haven't had the time to dig into them. |
|
FWIW I decided to write my own extension. |
As previously discussed in PR 20 and now mentioned in issue 30, dealing with remote tracking trees currently does not have a good user experience. This pull request addresses this, while also adding a necessary feature to make that experience even smoother: switching directories back to the bare repository. Finally, a few minor fixes.
There are still some rough edges mentioned in some new TODOs and other minor stuff like properly announcing when the jobs ended, but those can be addressed later.