fix: use main repo when listing worktrees#2615
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates the worktree listing implementation to consistently enumerate from the main repository, enrich each entry with HEAD/branch details, and align output formatting for human-readable display.
Changes:
- Switch enumeration logic to use
main_repoand gather worktree data into a structured representation. - Add
WorktreeInfoand a formatter to print aligned base/head/branch columns. - Include short HEAD IDs and branch (or detached) status for each worktree.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4ab146012d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".
|
Thanks, needs review comments to be addressed (and rejection is an option). Also note that the |
|
I removed the review`checkbox to avoid confusion. The code wasn’t generated by AI; I had added that checkbox because I saw similar ones in other PRs. I replied to the review threads and committed the changes for the review comments I agreed with. I re-ran CI, but ci/test still seems to be failing. From what I saw, it looks similar to failures on other PRs as well. |
| let head = repo.head_id().map_or_else( | ||
| |_| ZERO_HEAD.to_string(), | ||
| |id| id.to_hex_with_len(HEAD_LENGTH).to_string(), | ||
| ); |
| } | ||
| for proxy in repo.worktrees()? { | ||
|
|
||
| let path_width = worktrees.iter().map(|worktree| worktree.base.len()).max().unwrap_or(0); |
|
|
||
| let branch = repo.head_name()?.map_or_else( | ||
| || "<detached>".to_string(), | ||
| |name| name.shorten().to_owned().to_string(), |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 08219d4dda
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".
| let head = repo.head_id().map_or_else( | ||
| |_| ZERO_HEAD.to_string(), | ||
| |id| id.to_hex_with_len(HEAD_LENGTH).to_string(), |
There was a problem hiding this comment.
Don’t mask all HEAD lookup failures as null OIDs
create_worktree_info() currently turns any repo.head_id() error into 000000000, but head_id() fails for more than just unborn branches (for example when HEAD points to an object ID that exists in refs but the object is missing/corrupt). In that case git worktree list still reports the abbreviated ref target, whereas this change silently reports a null OID, which misrepresents the checked-out revision and hides repository corruption. Limit the null-OID fallback to the unborn-HEAD case instead of swallowing every error.
Useful? React with 👍 / 👎.
Reported issue
gix worktree listdisplayed different kinds of information in the final column depending on the row.When run from a linked worktree, the command used the current worktree as the first row, and then listed linked worktrees from the repository metadata. This could cause the current linked worktree to appear twice while the main worktree was omitted.
This also made the output differ from
git worktree list, where the main worktree is listed first and the final column consistently shows the checked-out branch, or detached HEAD state.Closes #1649.
Summary
git worktree listmore closely.Git reference
git worktree listlists the main worktree first, followed by linked worktrees. Its final column describes the checked-out branch or detached HEAD state for each worktree, rather than the internal worktree ID.Validation
cargo fmtcargo check -p gitoxide-corecargo check -p gitoxidecargo test -p gitoxide -- worktreegix worktree listwithgit worktree listfrom: