Add subcommand branch show-base#118
Conversation
Introduces a local caching layer for the resolved base (target) branch of local feature branches, avoiding redundant Forge API network calls.
andrew
left a comment
There was a problem hiding this comment.
Thanks for picking this up. The design follows #115 closely and the user-facing surface is small. A few changes to request before merge:
1. Move git/ under internal/. Every other helper package here (internal/resolve, internal/output, internal/config) is internal/. A top-level git/ commits GetOrFetchBaseBranch as a public API. Unless that's intentional, please move it to internal/git/.
2. Deduplicate the cache-write sites. The new git package owns the branch.<name>.forge-merge-base key format, but internal/cli/pr.go reformats it inline in three places (prViewCmd, prCreateCmd, the checkout block). Please add an exported helper in the git package (e.g. SetBaseBranch(ctx, branch, base)) and route all three sites through it.
3. pr view can mis-cache against an unrelated local branch. In prViewCmd the cache write fires whenever a local branch happens to share a name with pr.Head.Ref, even for fork PRs where the local branch tracks something else. Please skip the cache write when pr.Head.Fork != nil, or check branch.<name>.remote/merge to confirm the local branch actually corresponds to the PR head.
4. Head-matching loop in GetOrFetchBaseBranch. ListPROpts.Head is already passed as a filter, so the per-PR pr.Head.Ref == branch || strings.HasSuffix(pr.Head.Ref, ":"+branch) check is either redundant or compensating for a backend that ignores the filter. If the latter, the suffix branch can match an unrelated fork PR with the same branch name. Please either drop the client-side check or add a comment explaining which forge needs it.
5. Test uses os.Chdir. git/git_test.go mutates process-wide cwd, which precludes t.Parallel() and is fragile if other tests in the package ever run alongside it. Prefer running git with -C tmpDir (you'd need to thread a working dir into the production function), or document the constraint.
Minor:
git/git.gohas no package doc comment.- Mock
Listignoresopts— a smallopts.Head == "feature-xyz"assertion would catch a future refactor that drops the API-side filter. -rcollides conceptually with "recursive" elsewhere;--refreshonly might be clearer, but not blocking.
- Move git package to internal/git - Deduplicate cache-write sites using git.SetBaseBranch helper - Skip cache-write in pr view if PR is from a fork - Refactor git_test to avoid os.Chdir by passing/setting directory context - Clean up client-side Head filtering in GetOrFetchBaseBranch with comment
|
I have addressed the PR review feedback:
|
Description
Resolves #115.
Introduces a local caching layer for the resolved base (target) branch of local feature branches, avoiding redundant Forge API network calls.
Changes
gitpackage withGetOrFetchBaseBranchto check for and setbranch.<branch>.forge-merge-basein.git/config.forge branch show-base [branch](with-r/--refreshflag to bypass/update the cache).forge pr checkout: Caches base branch for the checked-out branch.forge pr create: Caches base branch for the source branch.forge pr view: Caches base branch if the source branch exists locally.git_test.goand CLI command validation.