Skip to content

show worktree locations in av tree output#675

Merged
aviator-app[bot] merged 2 commits intomasterfrom
tree-show-worktrees
Mar 13, 2026
Merged

show worktree locations in av tree output#675
aviator-app[bot] merged 2 commits intomasterfrom
tree-show-worktrees

Conversation

@tulioz
Copy link
Contributor

@tulioz tulioz commented Mar 11, 2026

branches checked out in worktrees now show the worktree directory name next to them

@tulioz tulioz requested a review from a team as a code owner March 11, 2026 23:56
@aviator-app
Copy link
Contributor

aviator-app bot commented Mar 11, 2026

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This PR was merged using Aviator.


See the real-time status of this PR on the Aviator webapp.
Use the Aviator Chrome Extension to see the status of your PR within GitHub.

@aviator-app
Copy link
Contributor

aviator-app bot commented Mar 11, 2026

✅ FlexReview Status

Common Owner: aviator-co/engineering (expert-load-balance assignment)
Owner and Assignment:

  • aviator-co/engineering (expert-load-balance assignment)
    Owned Files
    • 🔒 cmd/av/tree.go
    • 🔒 internal/git/worktree.go

Review SLO: 7 business hours if PR size is <= 200 LOC for the first response.

@aviator-app aviator-app bot requested a review from davi-maciel March 11, 2026 23:56
@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 enhances the av tree command by integrating Git worktree information directly into its output. This change provides users with immediate visibility into which branches are associated with active worktrees and their corresponding directory names, streamlining the workflow for developers managing multiple Git worktrees.

Highlights

  • Worktree Visibility: The av tree command now displays the directory name for branches checked out in Git worktrees, providing clearer context for developers.
  • Worktree Listing Utility: A new internal Git utility was introduced to programmatically list and parse Git worktree information, enabling its integration into the av tree output.

🧠 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
  • cmd/av/tree.go
    • Imported the path/filepath package to handle file paths.
    • Added logic to list Git worktrees and map them by branch name for easy lookup.
    • Modified the renderStackTreeBranchInfo function to accept and utilize worktree information for display.
    • Updated the branch rendering to include worktree names next to the branch if it's a worktree branch.
  • internal/git/worktree.go
    • Added a new file defining the WorktreeInfo struct to hold worktree details.
    • Implemented the WorktreeList function to execute git worktree list --porcelain.
    • Added parsing logic to extract worktree path, HEAD commit, and branch name from the Git command output.
Activity
  • No human activity has been recorded on this pull request yet.
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 adds a useful feature to display worktree locations in the av tree output. The implementation is mostly correct, but I have a couple of suggestions. First, an error returned from listing worktrees is currently ignored, which should be handled to provide feedback to the user in case of failure. Second, the parsing logic for the git worktree list output in the new internal/git/worktree.go file uses a Go 1.22 feature and can be refactored for better compatibility and readability. I've provided suggestions for both points.

return err
}

worktrees, _ := repo.WorktreeList(ctx)

Choose a reason for hiding this comment

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

high

The error returned by repo.WorktreeList(ctx) is ignored. If the command fails (e.g., due to a Git error), this will fail silently. The error should be handled by printing a warning to the user so they are aware that the worktree information might be missing.

		worktrees, err := repo.WorktreeList(ctx)
		if err != nil {
			// Not a fatal error, just print a warning and continue.
			_, _ = fmt.Fprintf(cmd.ErrOrStderr(), "warning: could not read worktree locations: %v\n", err)
		}

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Comment on lines +24 to +45
var worktrees []WorktreeInfo
var current WorktreeInfo
for line := range strings.SplitSeq(out, "\n") {
if line == "" {
if current.Path != "" {
worktrees = append(worktrees, current)
}
current = WorktreeInfo{}
continue
}
if rest, ok := strings.CutPrefix(line, "worktree "); ok {
current.Path = rest
} else if rest, ok := strings.CutPrefix(line, "HEAD "); ok {
current.HEAD = rest
} else if rest, ok := strings.CutPrefix(line, "branch "); ok {
current.Branch = strings.TrimPrefix(rest, "refs/heads/")
}
}
if current.Path != "" {
worktrees = append(worktrees, current)
}
return worktrees, nil

Choose a reason for hiding this comment

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

high

The use of for line := range strings.SplitSeq(out, "\n") requires Go 1.22. For better compatibility with older Go versions, it's safer to use strings.Split. Additionally, the parsing logic can be simplified by splitting the output into records first, which also removes the duplicated code for appending the last worktree. This improves readability and maintainability.

Suggested change
var worktrees []WorktreeInfo
var current WorktreeInfo
for line := range strings.SplitSeq(out, "\n") {
if line == "" {
if current.Path != "" {
worktrees = append(worktrees, current)
}
current = WorktreeInfo{}
continue
}
if rest, ok := strings.CutPrefix(line, "worktree "); ok {
current.Path = rest
} else if rest, ok := strings.CutPrefix(line, "HEAD "); ok {
current.HEAD = rest
} else if rest, ok := strings.CutPrefix(line, "branch "); ok {
current.Branch = strings.TrimPrefix(rest, "refs/heads/")
}
}
if current.Path != "" {
worktrees = append(worktrees, current)
}
return worktrees, nil
var worktrees []WorktreeInfo
// Each worktree record is separated by a blank line.
for _, record := range strings.Split(out, "\n\n") {
var current WorktreeInfo
for _, line := range strings.Split(record, "\n") {
if rest, ok := strings.CutPrefix(line, "worktree "); ok {
current.Path = rest
} else if rest, ok := strings.CutPrefix(line, "HEAD "); ok {
current.HEAD = rest
} else if rest, ok := strings.CutPrefix(line, "branch "); ok {
current.Branch = strings.TrimPrefix(rest, "refs/heads/")
}
}
if current.Path != "" {
worktrees = append(worktrees, current)
}
}
return worktrees, nil

@davi-maciel davi-maciel requested review from jainankit and removed request for davi-maciel March 12, 2026 02:11
@aviator-app aviator-app bot merged commit 3470da4 into master Mar 13, 2026
4 of 5 checks passed
@aviator-app aviator-app bot deleted the tree-show-worktrees branch March 13, 2026 17:39
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