@devries-cameron20 / t3code-1 / commits / d1ecacda43
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Polish git worktree helpers after rebase

Co-authored-by: codex <codex@users.noreply.github.com>

Julius Marminge committed Feb 9, 2026 at 23:38 UTC d1ecacda43718b0a96e9fca1cd7d30f82a64a574
2 files changed +9 -16
apps/desktop/src/git.test.ts
-10
@@ -404,16 +404,6 @@ describe("git integration", () => {
404 await git(tmp.path, "add .");
405 await git(tmp.path, "commit -m 'diverge'");
406
407 - // Go back to default branch
408 - const defaultBranch = (await git(tmp.path, "rev-parse --abbrev-ref HEAD")).includes(
409 - "diverged",
410 - )
411 - ? // we're on diverged, need to find the other one
412 - (await listGitBranches({ cwd: tmp.path })).branches.find(
413 - (b) => !b.current && b.name !== "diverged",
414 - )!.name
415 - : await git(tmp.path, "rev-parse --abbrev-ref HEAD");
416 -
407 // Actually, let's just get back to the initial branch explicitly
408 const allBranches = await listGitBranches({ cwd: tmp.path });
409 const initialBranch = allBranches.branches.find((b) => b.name !== "diverged")!.name;
apps/desktop/src/git.ts
+9 -6
@@ -14,6 +14,10 @@ import type {
14 TerminalCommandResult,
15 } from "@t3tools/contracts";
16
17 +function escapeSingleQuotes(value: string): string {
18 + return value.replace(/'/g, "'\\''");
19 +}
20 +
21 export async function runTerminalCommand(
22 input: TerminalCommandInput,
23 ): Promise<TerminalCommandResult> {
@@ -111,7 +115,7 @@ export async function listGitBranches(
115 current: line.startsWith("* "),
116 isDefault: line.replace(/^[*+]\s+/, "") === defaultBranch,
117 }))
114 - .sort((a, b) => {
118 + .toSorted((a, b) => {
119 if (a.current !== b.current) return a.current ? -1 : 1;
120 if (a.isDefault !== b.isDefault) return a.isDefault ? -1 : 1;
121 return a.name.localeCompare(b.name);
@@ -123,7 +127,6 @@ export async function listGitBranches(
127 export async function createGitWorktree(
128 input: GitCreateWorktreeInput,
129 ): Promise<GitCreateWorktreeResult> {
126 - const esc = (s: string) => s.replace(/'/g, "'\\''");
130 const sanitizedBranch = input.newBranch.replace(/\//g, "-");
131 const repoName = path.basename(input.cwd);
132 const worktreePath =
@@ -132,7 +135,7 @@ export async function createGitWorktree(
135
136 // Create a new branch from the base branch in a new worktree
137 const result = await runTerminalCommand({
135 - command: `git worktree add -b '${esc(input.newBranch)}' '${esc(worktreePath)}' '${esc(input.branch)}'`,
138 + command: `git worktree add -b '${escapeSingleQuotes(input.newBranch)}' '${escapeSingleQuotes(worktreePath)}' '${escapeSingleQuotes(input.branch)}'`,
139 cwd: input.cwd,
140 timeoutMs: 30_000,
141 });
@@ -153,7 +156,7 @@ export async function removeGitWorktree(
156 input: GitRemoveWorktreeInput,
157 ): Promise<void> {
158 const result = await runTerminalCommand({
156 - command: `git worktree remove '${input.path.replace(/'/g, "'\\''")}'`,
159 + command: `git worktree remove '${escapeSingleQuotes(input.path)}'`,
160 cwd: input.cwd,
161 timeoutMs: 15_000,
162 });
@@ -167,7 +170,7 @@ export async function createGitBranch(
170 input: GitCreateBranchInput,
171 ): Promise<void> {
172 const result = await runTerminalCommand({
170 - command: `git branch '${input.branch.replace(/'/g, "'\\''")}'`,
173 + command: `git branch '${escapeSingleQuotes(input.branch)}'`,
174 cwd: input.cwd,
175 timeoutMs: 10_000,
176 });
@@ -181,7 +184,7 @@ export async function checkoutGitBranch(
184 input: GitCheckoutInput,
185 ): Promise<void> {
186 const result = await runTerminalCommand({
184 - command: `git checkout '${input.branch.replace(/'/g, "'\\''")}'`,
187 + command: `git checkout '${escapeSingleQuotes(input.branch)}'`,
188 cwd: input.cwd,
189 timeoutMs: 10_000,
190 });