Extract worktree list parsing into git client - #13953
Closed
tidy-dev wants to merge 3 commits into
Closed
Conversation
Promote the inline `git worktree list --porcelain` parsing from the pr/checkout command into a reusable `Client.Worktrees` method backed by a new `Worktree` type and pure `parseWorktrees` helper. Rewire `isWorktreeAtPath` to consume it so behavior is unchanged. This gives the follow-up worktree subtasks (gh issue develop --worktree, gh pr merge --delete-branch guards) a shared, tested parser instead of each re-implementing porcelain parsing. Co-authored-by: Copilot App <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR performs a small, behavior-preserving refactor in the GitHub CLI by extracting git worktree list --porcelain parsing from gh pr checkout into the shared git.Client, enabling reuse by other commands that need to inspect worktrees.
Changes:
- Introduces a
git.Worktreeobject model forgit worktree list --porcelainentries. - Adds
Client.Worktrees(ctx)and a dedicatedparseWorktreeshelper in the shared git client. - Updates
pr checkoutworktree path detection to use the new shared API and adds unit tests for both the client method and parser.
Show a summary per file
| File | Description |
|---|---|
| pkg/cmd/pr/checkout/checkout.go | Switches worktree-at-path detection to use the new shared Client.Worktrees method. |
| git/objects.go | Adds a Worktree struct to represent parsed worktree entries. |
| git/client.go | Adds Client.Worktrees(ctx) and parseWorktrees implementation. |
| git/client_test.go | Adds coverage for Client.Worktrees and parseWorktrees across key scenarios. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Low
tidy-dev
marked this pull request as draft
July 23, 2026 17:18
Drop the Head, Detached, and Bare fields. None of the worktree subtasks read the checked-out SHA, and detached/bare worktrees are handled by simply having an empty Branch, so the extra fields were speculative. The parser still tolerates HEAD/detached/bare lines; it just ignores them. Co-authored-by: Copilot App <[email protected]>
tidy-dev
marked this pull request as ready for review
July 23, 2026 17:31
…nto tidy-dev-worktree-client-helper # Conflicts: # pkg/cmd/pr/checkout/checkout.go
Contributor
Author
|
Closing - this content is now absorbed into #13955 which targets trunk directly. |
An error occurred while trying to automatically change base from
tidy-dev-pr-checkout-worktree
to
trunk
August 4, 2026 11:47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Small, behavior-preserving refactor stacked on top of #13946 (
gh pr checkout --worktree). It promotes the inlinegit worktree list --porcelainparsing out of thepr/checkoutcommand and into the shared git client so the remaining worktree subtasks can reuse it.Worktreetype ingit/objects.go(Path, Head, Branch, Detached, Bare).Client.Worktrees(ctx)ingit/client.go, backed by a pureparseWorktreeshelper, following the existingRemotes/parseRemotesandShowRefsconventions.isWorktreeAtPathinpkg/cmd/pr/checkout/checkout.goto consume the new method (no behavior change).TestClientWorktreesandTest_parseWorktreescovering normal, multiple, detached, bare, and no-trailing-newline records.Why
The two follow-up subtasks under epic github/gh-cli-and-desktop#258 (
gh issue develop --worktreeandgh pr merge --delete-branchworktree guards) both need to inspect existing worktrees. Extracting one tested parser avoids each command re-implementing porcelain parsing.Stacking
This PR is based on
tidy-dev-pr-checkout-worktree(#13946). Review/merge that PR first; the diff here is only the parser extraction.Testing
go test ./git/... ./pkg/cmd/pr/checkout/...— new and existing worktree tests pass. (TestClientLastCommitfails in my local sandbox due to asafe.bareRepositorygit config, unrelated to this change and pre-existing on the base branch.)go vetandgofmtclean.Co-authored-by: Copilot App [email protected]