Skip to content

feat: sibling directory standard and tmux session integration for worktrees - #43

Open
felipecm-br wants to merge 1 commit into
Blankeos:mainfrom
felipecm-br:feat/worktree-tmux-bare
Open

felipecm-br wants to merge 1 commit into
Blankeos:mainfrom
felipecm-br:feat/worktree-tmux-bare

Conversation

@felipecm-br

Copy link
Copy Markdown
Contributor

Description

Improves worktree management with support for sibling directory creation layouts (especially useful with .bare repository standard) and seamless Tmux/session manager integration.

Details

  • Sibling directory resolution: Worktrees are created cleanly as sibling folders (../<branch>) with slugged names (e.g. feat/login -> feat-login), preserving repository structure without cluttering the parent workspace.
  • Base tracking configuration: Automatically sets branch.<name>.base in git config for downstream tooling.
  • Tmux / WM session switching:
    • Adds shortcut t on selected worktrees to open directly in a dedicated Tmux session (supporting wm connect, sesh connect, or native tmux switch-client / new-session).
    • Presents an interactive action menu on worktree switch/create (Open in Tmux, Open lazygitrs in terminal, Stay in current worktree).
  • Post-create hook support: Runs lifecycle hook if defined under ~/.config/lazygitrs/hooks/post-create.sh or ~/.config/matchmaker/hooks/post-create.sh.
  • Comprehensive unit tests covering path resolution, temp directory isolation, and git config verification.

Validation

  • cargo test --bin lazygitrs (all 373 tests passed)
  • cargo fmt --check

@Blankeos

Blankeos commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

feat/worktree-tmux-bare → main
Model: claude-sonnet-5-5, effort unknown

Confidence: 2/5

The sibling-directory create flow works on a .bare layout, but the PR's own new test fails on macOS, the tmux/sesh integration visibly corrupts or freezes the TUI, the old path branch input now errors, and the stored branch.<name>.base is the literal string HEAD.

Checks run

  • cargo fmt --check: clean. cargo test: 372 passed, 1 failed (main: 371 pass, 0 fail). The failure is the new git::worktree::tests::test_add_worktree_sibling_creation on macOS: left: /private/var/folders/.../feat-oauth-login, right: /var/folders/.../feat-oauth-login (repo path is canonicalized, the expected path isn't). Likely passes on Linux.
  • cargo clippy: new dead-code warning for create_worktree / create_worktree_new_branch, and a collapsible-if in open_in_tmux_session.
  • Ran the Linux release build in the VM (tmux 3.3a) with a .bare layout (bare/.bare, bare/main) and a normal repo (dev/proj next to dev/otherproj):
    • .bare: n → feat/login creates bare/feat-login; .env is copied from main/; the post-create hook runs with <path> feat/login main.
    • Normal repo: the same flow creates dev/feat-login in the shared parent directory next to unrelated projects.
    • branch.feat/login.base is HEAD when no base is typed (git config branch.feat/login.base HEAD in the command log), while the hook is told main. With an explicit base (fix/x main) it is main.
    • Old input ../old-wt feat2 now fails: git worktree add -b ../old-wt /tmp/.../..-old-wt feat2 → '../old-wt' is not a valid branch name. No worktree or branch is created.
    • t with a fake sesh on PATH: .status() blocks the event loop ~4s and its stdout is printed straight over the TUI (screenshot).
    • t inside tmux: tmux new-session -d -s fix-x works (session created). I did not get a reliable attached client, so switch-client is unverified.
    • t outside tmux (TMUX unset): tmux new-session -A is spawned on the same tty while the TUI is still running. A nested shell prompt draws over the status bar and the TUI keeps consuming keys (my Down opened the checkout menu in the commits panel) (screenshot).

Summary

Thanks Felipe, the .bare-style sibling layout and the action menu after create are a good fit for how some people work. Blockers: (1) fix the macOS test; (2) the tmux/wm/sesh calls need to suspend the TUI (leave the alt screen, restore raw mode afterwards, like the terminal-editor path does) or run non-interactively, otherwise the screen corrupts; (3) n used to accept path branch; keep that as a fallback when the first token looks like a path (contains / + exists/../~, or two tokens where the second is an existing ref) or the error is confusing; (4) store a real base (git rev-parse --abbrev-ref HEAD) instead of HEAD, and pass the same value to the hook. Also worth discussing: the .env copy hard-codes a sibling named main, the hook runs from $HOME without being waited on or logged, and in a normal (non-.bare) repo the sibling path lands in the parent of the project, which is shared with other projects. I'd put hook + .env + tmux behind config and ship the sibling-path create flow alone. Space now opens a menu instead of the old confirm and the t key isn't in the help bar.

Map

flowchart LR
  n[worktrees.rs 'n' input] --> add[worktree.rs add_worktree]
  add --> sib[resolve_worktree_sibling_path]
  add --> base[branch.NAME.base]
  add --> env[copy ../main/.env]
  add --> hook[post-create.sh spawn]
  n --> menu[action menu t/o/s]
  menu --> tmux[open_in_tmux_session: wm / sesh / tmux]
  key[t key] --> tmux
Loading

Start at worktree.rs add_worktree, then open_in_tmux_session in controller/worktrees.rs.

Regressions

  • path branch input removed; old input errors (see above).
  • TUI corruption/freeze when t / "Open in new Tmux session" runs wm, sesh or tmux on the live terminal.
  • New test fails on macOS.
  • Normal repos get worktrees as siblings of the project folder.
  • branch.<name>.base = HEAD.
  • Space no longer asks for confirmation before leaving; it opens a 3-way menu.

Migrations

None. Writes branch.<name>.base into the repo's git config for new branches.

Before merging

  • Fix the macOS test (canonicalize the expected path)
  • Suspend the TUI around tmux/wm/sesh or run them non-interactively
  • Keep path branch working (or give a clear error)
  • Store a real base ref, not HEAD
  • Decide on config-gating for hook and .env copy; add t to the help bar

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.

2 participants