diff --git a/harness/pstack/claude-code/skills/poteto-mode/scripts/orch/orch.test.ts b/harness/pstack/claude-code/skills/poteto-mode/scripts/orch/orch.test.ts index be8edd505..f0bef4315 100644 --- a/harness/pstack/claude-code/skills/poteto-mode/scripts/orch/orch.test.ts +++ b/harness/pstack/claude-code/skills/poteto-mode/scripts/orch/orch.test.ts @@ -592,6 +592,27 @@ describe("Store", () => { } }); + it(`resolves ${forge} branches when tags share their names`, async () => { + const { directory, store } = await initializedStore(); + const stack = await makeGitStack(directory); + git({ repo: stack.repo, args: ["tag", "stack/open", "main"] }); + git({ repo: stack.repo, args: ["tag", "stack/closed", "main"] }); + await withFakeForge({ + directory, forge, + operation: async () => { + const frontier = await store.frontier.set({ repo: stack.repo, forge }); + expect( + frontier.prs.map((row) => [row.branches, row.sha]) + ).toEqual([ + ["stack/merged", stack.mergedSha], + ["stack/closed", stack.closedSha], + ["stack/open", stack.openSha], + ["stack/draft", stack.draftSha], + ]); + }, + }); + }); + it(`still rejects multiple active ${forge} PRs on one branch`, async () => { const { directory, store } = await initializedStore(); const stack = await makeGitStack(directory); diff --git a/harness/pstack/claude-code/skills/poteto-mode/scripts/orch/store.ts b/harness/pstack/claude-code/skills/poteto-mode/scripts/orch/store.ts index a7cef5af8..a675db12b 100644 --- a/harness/pstack/claude-code/skills/poteto-mode/scripts/orch/store.ts +++ b/harness/pstack/claude-code/skills/poteto-mode/scripts/orch/store.ts @@ -1162,7 +1162,10 @@ function branchSha({ branch: string; repo: string; }): string { - const sha = runGit({ args: ["rev-parse", branch], repo }); + const sha = runGit({ + args: ["rev-parse", "--verify", `refs/heads/${branch}^{commit}`], + repo, + }); if (!/^[0-9a-f]{40,64}$/i.test(sha)) { throw new UserError(`git rev-parse ${branch} returned an invalid SHA`); } @@ -1170,7 +1173,11 @@ function branchSha({ } function currentBranch(repo: string): string { - return runGit({ args: ["symbolic-ref", "--short", "HEAD"], repo }); + // --short abbreviates to heads/ when a tag shares the branch name. + return runGit({ args: ["symbolic-ref", "HEAD"], repo }).replace( + /^refs\/heads\//, + "" + ); } function trunkBranch(repo: string): string { diff --git a/pstack/skills/poteto-mode/scripts/orch/orch.test.ts b/pstack/skills/poteto-mode/scripts/orch/orch.test.ts index be8edd505..f0bef4315 100644 --- a/pstack/skills/poteto-mode/scripts/orch/orch.test.ts +++ b/pstack/skills/poteto-mode/scripts/orch/orch.test.ts @@ -592,6 +592,27 @@ describe("Store", () => { } }); + it(`resolves ${forge} branches when tags share their names`, async () => { + const { directory, store } = await initializedStore(); + const stack = await makeGitStack(directory); + git({ repo: stack.repo, args: ["tag", "stack/open", "main"] }); + git({ repo: stack.repo, args: ["tag", "stack/closed", "main"] }); + await withFakeForge({ + directory, forge, + operation: async () => { + const frontier = await store.frontier.set({ repo: stack.repo, forge }); + expect( + frontier.prs.map((row) => [row.branches, row.sha]) + ).toEqual([ + ["stack/merged", stack.mergedSha], + ["stack/closed", stack.closedSha], + ["stack/open", stack.openSha], + ["stack/draft", stack.draftSha], + ]); + }, + }); + }); + it(`still rejects multiple active ${forge} PRs on one branch`, async () => { const { directory, store } = await initializedStore(); const stack = await makeGitStack(directory); diff --git a/pstack/skills/poteto-mode/scripts/orch/store.ts b/pstack/skills/poteto-mode/scripts/orch/store.ts index a7cef5af8..a675db12b 100644 --- a/pstack/skills/poteto-mode/scripts/orch/store.ts +++ b/pstack/skills/poteto-mode/scripts/orch/store.ts @@ -1162,7 +1162,10 @@ function branchSha({ branch: string; repo: string; }): string { - const sha = runGit({ args: ["rev-parse", branch], repo }); + const sha = runGit({ + args: ["rev-parse", "--verify", `refs/heads/${branch}^{commit}`], + repo, + }); if (!/^[0-9a-f]{40,64}$/i.test(sha)) { throw new UserError(`git rev-parse ${branch} returned an invalid SHA`); } @@ -1170,7 +1173,11 @@ function branchSha({ } function currentBranch(repo: string): string { - return runGit({ args: ["symbolic-ref", "--short", "HEAD"], repo }); + // --short abbreviates to heads/ when a tag shares the branch name. + return runGit({ args: ["symbolic-ref", "HEAD"], repo }).replace( + /^refs\/heads\//, + "" + ); } function trunkBranch(repo: string): string {