Preserve local branch names when checking merge targets

This commit is contained in:
Mohamed Boudra
2026-11-03 07:53:15 +01:00
parent 46741065e5
commit b101e4ec16
2 changed files with 18 additions and 4 deletions
+17
View File
@@ -226,6 +226,23 @@ describe("git-actions-policy", () => {
expect(isCurrentBranchLocalMergeTarget("release", "refs/remotes/upstream/release")).toBe(false);
});
it("offers local merge when the selected local base starts with origin slash", () => {
const actions = buildGitActions(
createInput({
isPaseoOwnedWorktree: true,
isOnBaseBranch: isCurrentBranchBase("release", "refs/heads/origin/release"),
isOnLocalMergeTarget: isCurrentBranchLocalMergeTarget(
"release",
"refs/heads/origin/release",
),
baseRefLabel: "origin/release",
aheadCount: 1,
shipDefault: "merge",
}),
);
expect(actions.primary?.id).toBe("merge-branch");
});
it("does not offer merging into the current local branch when the remote base shares its name", () => {
const actions = buildGitActions(
createInput({
+1 -4
View File
@@ -66,10 +66,7 @@ export function isCurrentBranchLocalMergeTarget(
baseRef: string | null | undefined,
): boolean {
if (!currentBranch || !baseRef) return false;
const localTarget = baseRef
.replace(/^refs\/heads\//, "")
.replace(/^refs\/remotes\/origin\//, "")
.replace(/^origin\//, "");
const localTarget = baseRef.replace(/^(?:refs\/heads\/|refs\/remotes\/origin\/|origin\/)/, "");
return currentBranch === localTarget;
}