-
Notifications
You must be signed in to change notification settings - Fork 80
Improve git root detection logic #195
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
|
Also, as a side effect of the new implementation, the issue described in #192 seems to be solved! 🎉 Tmux + gum example using the new |
|
Gotta fix tests, I'll DM you and we can do some pair programming to fix it. |
… some of this anyway.)
…ks for more consistent `git worktree list` logic.
|
When I choose a git worktree I got this result: But expected this:: |
|
Furthermore, when I call However, I need this to be the root so I can properly leverage the root search feature: |
|
I moved this to a draft for now, let me know if you want someone else to take over or have some time soon to revisit this work and finish it up, thanks! |
|
TLDR of recent changes: While |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR improves the git root detection logic by leveraging the output of "git worktree list" to determine the repository root, streamlining the handling of different git worktree conventions.
- Updated the Root command to inject new dependencies (git and home) and use GitRoot for path resolution.
- Refactored the namer package to remove outdated methods and adjust tests accordingly.
- Updated the Git interface and its mocks, along with test coverage for new git root logic.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| seshcli/seshcli.go | Updated CLI registration with new dependencies for the root cmd. |
| seshcli/root.go | Modified root command implementation to use GitRoot and Home. |
| namer/namer_test.go | Adjusted tests to reflect changes from GitCommonDir/ShowTopLevel to GitRoot. |
| namer/namer.go | Removed the gitBareName strategy for git root detection. |
| namer/git.go | Refactored git name resolution to use GitRoot. |
| git/mock_Git.go | Updated mocks to support GitRoot instead of deprecated methods. |
| git/git_test.go | Added tests covering new worktree list based GitRoot implementation. |
| git/git.go | Refactored GitRoot to use "git worktree list" and trim .bare suffix. |
| dir/dir.go | Simplified root directory detection by directly calling GitRoot. |
|
I'm looking over the code and there's a breaking change I need fixed: When calling sesh root on a worktree, I need the "root" to be the worktree folder, not the place the bare worktree is installed. |
joshmedeski
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some additional feedback on where we want the logic to live, nice work overall and I'm looking forward to getting this merged soon 🫶
| cli "github.com/urfave/cli/v2" | ||
| ) | ||
|
|
||
| func Root(l lister.Lister, n namer.Namer) *cli.Command { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With my request to move the logic of determining the name in the namer package, we can reverse this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did move the name parsing logic into the namer package as you requested 👍, but need to think on how we want to wire it up in the dir package. Do we just import the namer, or dependency inject it? Maybe we can pair on this 🤔
0b1d01a to
700b49e
Compare
700b49e to
077a98c
Compare
|
Is this PR is in consideration? |
|
Yes, the development was paused for a while. I would like to pick it up and finish it soon. |
|
The work has been moved to #288 |
|
@jesseleite can you share how you are listing branches in sesh for git worktree? I was thinking something like I am using the https://github.com/nix-community/home-manager/blob/9a2dc0efbc569ce9352a6ffb8e8ec8dbc098e142/modules/programs/sesh.nix#L95-L109 currenlty for listing. |
|
@niksingh710 this is how I work with git worktrees and sesh: I always do a bare clone of the repo that I want to use for worktrees. Typically the directory is a short abbreviation (since sesh is only 4 characters, I bare clone to My git worktrees are simple directory names, typically feature-focused. For example, if I'm working on updating a git-bare-namer feature for sesh I'd create a worktree called Then, I setup this custom sesh configuration if I ever want to explicitly pick a sesh worktree: [[session]]
name = "sesh pick worktree"
path = "~/c/sesh"
startup_command = "sesh connect (find . -maxdepth 1 -type d | gum filter --limit 1 --fuzzy --no-sort --placeholder 'Pick a worktree' --prompt='🌲') && exit"Note The |


Firstly, a quick thank you, for all your awesome work on sesh! It's a game changer for me ❤️
The problem:
The sesh README says that
sesh rootassumes existence of a.barefolder...Not everyone uses git worktrees this way. For example, many prefer the conventional
git clone --bare [repo] project, which leaves you with a messy project folder, but this is still very common nonetheless.I on the other hand, prefer to run
git clone --bare [repo] project/.git, which stores all of the git meta in.gitfolder, but still creates a bare repo. This leaves me with a really clean project folder when using worktrees...The
.bareconvention is cool too, but again would require different pathing logic for each situation.A possible solution:
My proposition is to use the output of
git worktree list, since git knows where the main worktree / bare repo lives...^ As you can see, the main worktree is always listed first, no matter how you roll with git worktrees (whether that be using
.git, or.bare, or doing it the messier default way.For example, this is what you see when running
git worktree list...This PR uses
git worktree listto grab that first field, for the basis ofsesh rootand also for thenamerpackage used when naming sessions.I was able to remove both
--git-common-dirand--show-toplevelchecks, because those seem to be handled well with the first field returned bygit worktree list; It seems to be super consistent across all situations 🎉Todo:
git worktree listto find root from within git worktree repos.bareconvention.gitconventiongit worktree listto find root from non-worktree repo subdirssesh rootcommandnamerpackage