Skip to content

Show worktree subpath when custom - #9

Merged
melonamin merged 7 commits into
melonamin:mainfrom
mishamsk:mp/show-folder-if-different-from-worktree-branch
Apr 29, 2026
Merged

melonamin merged 7 commits into
melonamin:mainfrom
mishamsk:mp/show-folder-if-different-from-worktree-branch

Conversation

@mishamsk

@mishamsk mishamsk commented Feb 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When a worktree's folder name doesn't match its checked-out branch (e.g. branch feature/login in folder old-experiment), show a visual indicator so users know the folder is non-standard.

Display format

Scenario Display
Normal worktree branch ✓ ↑1 commit text (2h ago)
Folder mismatch, wide terminal branch [📂 folder-name] │ ✓ ↑1 commit text (2h ago)
Folder mismatch, narrow terminal branch [📂] │ ✓ ↑1 commit text (2h ago)

Visibility rules

  • Main repo (where .git lives): never shows folder indicator — it's always expected
  • Matching worktrees: folder name matches the branch name convention (/ → -) — no indicator
  • Mismatched worktrees: shows [📂 folder-name] when terminal is wide enough to also fit the commit text; collapses to [📂] when space is tight
  • A │ pipe separates the worktree identity section from the status/commit tail

Changes

  • Added mainWorktreeDir tracking (first entry from git worktree list) to correctly identify the main repo regardless of which worktree gt is launched from
  • Replaced full-path comparison with isExpectedWorktreePath that compares just the folder basename
  • Removed path truncation helpers (truncatePathTail, tailStringByWidth, truncateStringByWidth) in favor of simple show-or-hide logic
  • Added truncateToWidth for display-width-aware string truncation
  • Cleaned up unused go-runewidth direct import, math import, and related constants

Test plan

  • TestIsExpectedWorktreePath — validates branch-to-folder matching for simple names, slashed branches, mismatches, and edge cases
  • TestTruncateToWidth — validates width-aware truncation with ellipsis
  • Manual testing with real worktrees showing matching/mismatching folder names at various terminal widths

@codecov-commenter

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@mishamsk
mishamsk marked this pull request as draft February 3, 2026 16:32
@melonamin

Copy link
Copy Markdown
Owner

@mishamsk still in progress or forgot to un-draft?

@mishamsk

mishamsk commented Feb 9, 2026

Copy link
Copy Markdown
Contributor Author

Draft still. I wanted to improve how it shortens the path. Currently stupid. Didn't get to it yet, sorry. But I have vested interest in this pr, so rest assured it is coming

Instead of truncating both commit text and folder path to fit narrow
screens, hide the subpath entirely when it doesn't fit and only show
the commit detail. This is more readable than showing truncated paths.
Three fixes for worktree folder path display:
- Don't show path for the main worktree (where .git lives)
- Fix branch-to-folder matching by comparing just the folder basename
  instead of computing the full expected path from repoPath (which
  could be a worktree path itself, not the main repo)
- Move folder path to appear after branch name, before status symbols
Replace the full folder path display with a compact ⧉ symbol to
indicate the worktree folder doesn't match the branch name. This
preserves space for the commit message which is more useful.
When the worktree folder doesn't match the branch name, show
"📂 folder-name" after the branch. If there isn't enough terminal
width to fit the folder name alongside the commit text, fall back
to showing just the 📂 icon as a compact indicator.
Wrap the folder mismatch indicator in square brackets ([📂 name]
or [📂]) and use a │ pipe to visually separate the worktree
name section from the status/commit tail.
@mishamsk
mishamsk marked this pull request as ready for review February 15, 2026 03:40
@mishamsk

Copy link
Copy Markdown
Contributor Author

@melonamin ready (although not entirely sure about bare folder symbol for narrow display, maybe you have better ideas)

@mishamsk

Copy link
Copy Markdown
Contributor Author

@melonamin maybe merge this one?

@melonamin
melonamin merged commit d110e21 into melonamin:main Apr 29, 2026
5 checks passed
melonamin added a commit that referenced this pull request Apr 30, 2026
Release includes:
- Show worktree subpath when folder name doesn't match branch (#9)
@mishamsk
mishamsk deleted the mp/show-folder-if-different-from-worktree-branch branch June 2, 2026 19:35
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