Skip to content

Commit 38bf4ab

Browse files
committed
Address review feedback (round 2)
- Add `--` separator to git fetch in fetchRef so a ref beginning with `-` can't be parsed as an option, matching remoteBranchExists. - Add a fetch-failure test for createWorktreeForRemoteBranch. - Drop the redundant onClick on the dialog Cancel button; onOpenChange already drives cancel, mirroring BranchMismatchDialog.
1 parent e3ed6d3 commit 38bf4ab

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

packages/git/src/queries.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,8 @@ export async function fetchRef(
10731073
ref: string,
10741074
): Promise<boolean> {
10751075
try {
1076-
await git.raw(["fetch", "--quiet", "--no-tags", remote, ref]);
1076+
// `--` keeps a ref beginning with `-` from being parsed as an option.
1077+
await git.raw(["fetch", "--quiet", "--no-tags", remote, "--", ref]);
10771078
return true;
10781079
} catch {
10791080
return false;

packages/git/src/worktree.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,22 @@ describe("WorktreeManager.createWorktreeForRemoteBranch", () => {
285285
).trim();
286286
expect(upstream).toBe("origin/contributor/pr");
287287
});
288+
289+
it("rejects when the remote branch cannot be fetched", async () => {
290+
// Point origin at a path that does not exist so the fetch fails.
291+
await createGitClient(localDir).remote([
292+
"set-url",
293+
"origin",
294+
"/nonexistent/path/to/remote",
295+
]);
296+
297+
const manager = new WorktreeManager({
298+
mainRepoPath: localDir,
299+
worktreeBasePath: worktreeBaseDir,
300+
});
301+
302+
await expect(
303+
manager.createWorktreeForRemoteBranch("contributor/pr"),
304+
).rejects.toThrow(/Failed to fetch branch 'contributor\/pr'/);
305+
});
288306
});

packages/ui/src/features/task-detail/components/RemoteBranchCheckoutDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function RemoteBranchCheckoutDialog() {
3535

3636
<Flex justify="end" gap="2" mt="4">
3737
<AlertDialog.Cancel>
38-
<Button variant="soft" color="gray" size="1" onClick={cancel}>
38+
<Button variant="soft" color="gray" size="1">
3939
Cancel
4040
</Button>
4141
</AlertDialog.Cancel>

0 commit comments

Comments
 (0)