Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/scoring/diff-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ diff --git a/b.ts b/b.ts
it("handles empty diff", () => {
assert.deepEqual(parseDiff(""), []);
});

it("handles filenames with spaces (quoted paths)", () => {
const quotedDiff = `diff --git "a/src/my component.tsx" "b/src/my component.tsx"
--- "a/src/my component.tsx"
+++ "b/src/my component.tsx"
@@ -1 +1 @@
+export default function MyComponent() {}`;
const files = parseDiff(quotedDiff);
assert.equal(files.length, 1);
assert.equal(files[0]!.path, "src/my component.tsx");
});
});

describe("diffSimilarity", () => {
Expand Down
3 changes: 2 additions & 1 deletion src/scoring/diff-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export function parseDiff(diff: string): DiffFile[] {
for (const line of diff.split("\n")) {
// New file header: diff --git a/path b/path
if (line.startsWith("diff --git")) {
const match = line.match(/diff --git a\/(.+) b\/(.+)/);
// Handle both quoted and unquoted paths (spaces in filenames)
const match = line.match(/diff --git "?a\/(.+?)"? "?b\/(.+?)"?$/);
if (match?.[2]) {
current = { path: match[2], addedLines: [], removedLines: [] };
files.push(current);
Expand Down
3 changes: 2 additions & 1 deletion src/utils/git.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { execFile } from "node:child_process";
import { randomUUID } from "node:crypto";
import { mkdtemp, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
Expand All @@ -14,7 +15,7 @@ export async function getRepoRoot(): Promise<string> {
export async function createWorktree(id: number): Promise<string> {
const repoRoot = await getRepoRoot();
const dir = await mkdtemp(join(tmpdir(), `thinktank-agent-${id}-`));
const branchName = `thinktank/agent-${id}-${Date.now()}`;
const branchName = `thinktank/agent-${id}-${randomUUID().slice(0, 8)}`;

await exec("git", ["worktree", "add", "-b", branchName, dir], {
cwd: repoRoot,
Expand Down
Loading