Skip to content

Show parent project name in worktree status line#25

Merged
himattm merged 2 commits intomainfrom
show-parent-repo-in-worktree-statusline
Mar 11, 2026
Merged

Show parent project name in worktree status line#25
himattm merged 2 commits intomainfrom
show-parent-repo-in-worktree-statusline

Conversation

@himattm
Copy link
Owner

@himattm himattm commented Mar 10, 2026

Summary

  • When in a git worktree, the status line now shows ⎇ projectName/worktreeName instead of just ⎇ worktreeName
  • Parses the worktree's .git file (gitdir: /path/to/main/.git/worktrees/name) to trace back to the main repository
  • Result is cached with WorktreeTTL (5 min) to avoid repeated filesystem reads

Test plan

  • All 15 existing + new worktree/renderDir tests pass (go test ./internal/statusline/ -run "Worktree|MainRepo|RenderDir" -v)
  • Binary builds cleanly (go build ./cmd/prism/)
  • Manual: run claude --worktree and confirm status line shows ⎇ projectName/worktreeName

🤖 Generated with Claude Code

When running in a git worktree, the status line now shows
⎇ projectName/worktreeName instead of just ⎇ worktreeName,
by parsing the .git file to trace back to the main repository.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the user experience when working with Git worktrees by providing more contextual information directly in the status line. By displaying the parent repository's name alongside the worktree's name, users can more easily identify their current Git context, especially when managing multiple worktrees across different projects. The changes include robust parsing of Git metadata and a caching mechanism to ensure this enhancement does not negatively impact performance.

Highlights

  • Enhanced Worktree Display: The status line for Git worktrees now includes the parent project name, changing from '⎇ worktreeName' to '⎇ projectName/worktreeName' for improved context.
  • Main Repository Detection: Implemented new logic to parse the '.git' file within a worktree's root directory to accurately identify and extract the main repository's name.
  • Performance Optimization: The retrieval of the main repository name is now cached for 5 minutes ('WorktreeTTL') to prevent redundant filesystem reads and improve overall performance.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • internal/statusline/statusline.go
    • Modified 'renderDir' to prepend the main repository name to the worktree display name when in a worktree.
    • Added 'parseMainRepoName' function to read and parse the '.git' file in a worktree to determine the main repository's base name.
    • Introduced 'getMainRepoName' function, which wraps 'parseMainRepoName' with a caching mechanism to store results for 5 minutes.
  • internal/statusline/statusline_test.go
    • Updated existing 'TestRenderDir' tests ('WorktreeIndicator', 'CurrentDirInWorktree', 'CurrentDirInWorktreeSubdir') to verify the new 'mainRepoName/worktreeName' format in the status line.
    • Added 'TestGetMainRepoName_ValidWorktree' to confirm correct main repository name extraction for valid worktrees.
    • Added 'TestGetMainRepoName_MainRepo' to ensure 'getMainRepoName' returns an empty string for non-worktree main repositories.
    • Added 'TestParseMainRepoName_Fallbacks' to test error handling and edge cases for the 'parseMainRepoName' function, including non-existent directories, directories without '.git' files, and '.git' directories.
Activity
  • All 15 existing and new worktree/renderDir tests passed.
  • The binary builds cleanly.
  • Manual testing is suggested to confirm the status line display with 'claude --worktree'.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the status line for Git worktrees by displaying the parent project name, which is a great improvement for clarity. The implementation correctly parses the .git file to trace back to the main repository and thoughtfully includes caching to optimize performance. The tests have been updated appropriately, and new tests cover the added functionality. I have one suggestion to make the repository name parsing more robust in edge cases.

// e.g. /path/to/main-repo/.git/worktrees/name → /path/to/main-repo
sep := string(filepath.Separator)
marker := sep + ".git" + sep
idx := strings.Index(gitdir, marker)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using strings.LastIndex here would be more robust. The gitdir path points into the main repository's .git directory structure (.../main-repo/.git/worktrees/name). We want to find the .git directory of the main repository.

If a parent directory in the path happens to be named .git (e.g., /path/to/a.git/project/.git/worktrees/...), strings.Index would find the first /.git/ segment, leading to an incorrect main repository name (a.git instead of project).

Using strings.LastIndex ensures you find the .git directory that is closest to the worktrees directory in the path, which is the correct one for the main repository.

Suggested change
idx := strings.Index(gitdir, marker)
idx := strings.LastIndex(gitdir, marker)

Handles edge case where a parent directory contains .git in its name
(e.g., /path/to/a.git/project/.git/worktrees/name).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@himattm himattm merged commit 60b7a57 into main Mar 11, 2026
1 check passed
@himattm himattm deleted the show-parent-repo-in-worktree-statusline branch March 11, 2026 01:07
@himattm himattm mentioned this pull request Mar 11, 2026
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.

1 participant