Skip to content

Conversation

@jesseleite
Copy link

@jesseleite jesseleite commented Nov 3, 2024

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 root assumes existence of a .bare folder...

Note: This will only work if you are in a git worktree or git repository. For now, git worktrees expect a .bare folder.

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 .git folder, but still creates a bare repo. This leaves me with a really clean project folder when using worktrees...

CleanShot 2024-11-03 at 13 12 18

The .bare convention 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...

CleanShot 2024-11-03 at 13 13 09

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

CleanShot 2024-11-03 at 13 16 30

This PR uses git worktree list to grab that first field, for the basis of sesh root and also for the namer package used when naming sessions.

I was able to remove both --git-common-dir and --show-toplevel checks, because those seem to be handled well with the first field returned by git worktree list; It seems to be super consistent across all situations 🎉

Todo:

  • Proof of concept
    • Using git worktree list to find root from within git worktree repos
      • Using .bare convention
      • Using .git convention
      • With standard worktree (git config/refs/etc. files at root)
    • Using git worktree list to find root from non-worktree repo subdirs
  • Get working with sesh root command
  • Get working with namer package
  • Add test coverage

@jesseleite
Copy link
Author

jesseleite commented Nov 3, 2024

Also, as a side effect of the new implementation, the issue described in #192 seems to be solved! 🎉

CleanShot 2024-11-03 at 14 17 16

Tmux + gum example using the new sesh root functionality...

CleanShot 2024-11-03 at 14 21 31

@joshmedeski
Copy link
Owner

Gotta fix tests, I'll DM you and we can do some pair programming to fix it.

@joshmedeski joshmedeski self-requested a review November 5, 2024 22:21
@jesseleite jesseleite marked this pull request as ready for review November 7, 2024 02:53
@jesseleite jesseleite changed the title Improve sesh root logic Improve git root logic Nov 7, 2024
@jesseleite jesseleite changed the title Improve git root logic Improve git root detection logic Nov 7, 2024
@joshmedeski
Copy link
Owner

When I choose a git worktree I got this result:

_bare/Users/joshmedeski/c/sesh/v1

But expected this::

sesh/v1

@joshmedeski
Copy link
Owner

Furthermore, when I call sesh root I'm getting the following output:

~/c/sesh/.bare

However, I need this to be the root so I can properly leverage the root search feature:

~/c/sesh

@joshmedeski joshmedeski removed their request for review December 20, 2024 18:45
@joshmedeski joshmedeski marked this pull request as draft January 7, 2025 04:44
@joshmedeski
Copy link
Owner

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!

@jesseleite jesseleite marked this pull request as ready for review March 9, 2025 02:37
@jesseleite
Copy link
Author

TLDR of recent changes:

While git worktree list is still a much cleaner / more reliable solution than having to juggle between rev-parse --git-common-dir and --show-toplevel, I couldn't figure out how to get git to return without the .bare suffix, so I just restored your trim logic for .bare folder convention 👍

@joshmedeski joshmedeski self-requested a review April 18, 2025 01:11
@joshmedeski joshmedeski requested a review from Copilot April 18, 2025 01:11
Copy link
Contributor

Copilot AI left a 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.

@joshmedeski
Copy link
Owner

I'm looking over the code and there's a breaking change I need fixed:

sesh root
~/c/sesh

sesh root
~/c/sesh/main

When calling sesh root on a worktree, I need the "root" to be the worktree folder, not the place the bare worktree is installed.

Copy link
Owner

@joshmedeski joshmedeski left a 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 {
Copy link
Owner

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.

Copy link
Author

@jesseleite jesseleite Apr 18, 2025

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 🤔

@jesseleite jesseleite force-pushed the improved-sesh-root-logic branch 2 times, most recently from 0b1d01a to 700b49e Compare April 18, 2025 04:00
@jesseleite jesseleite force-pushed the improved-sesh-root-logic branch from 700b49e to 077a98c Compare April 18, 2025 04:02
@niksingh710
Copy link

Is this PR is in consideration?

@joshmedeski
Copy link
Owner

Yes, the development was paused for a while. I would like to pick it up and finish it soon.

@joshmedeski joshmedeski mentioned this pull request Sep 10, 2025
@joshmedeski
Copy link
Owner

The work has been moved to #288

@niksingh710
Copy link

@jesseleite can you share how you are listing branches in sesh for git worktree?

I was thinking something like repo:branchname for git worktree.

I am using the https://github.com/nix-community/home-manager/blob/9a2dc0efbc569ce9352a6ffb8e8ec8dbc098e142/modules/programs/sesh.nix#L95-L109 currenlty for listing.

@joshmedeski
Copy link
Owner

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

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 git-bare-namer.

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 && exit makes sure to close the picker session.
p.s. I hope to make this kind of functionality easier to configure and more intuitive in the near future.

@jesseleite jesseleite deleted the improved-sesh-root-logic branch September 30, 2025 12:59
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 this pull request may close these issues.

3 participants