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
34 changes: 34 additions & 0 deletions src/cli/commands/review.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,40 @@ describe("review staged-diff boundary", () => {
expect(sourceFile.stdout).toContain("CRITICAL fixture.ts:1");
});

test("treats staged filenames as literal git pathspecs", () => {
const repo = createRepo("literal-pathspec");
const fileName = ":(literal)fixture.ts";
writeFileSync(join(repo, fileName), `const token = "${syntheticGitHubToken}";\n`);
execFileSync("git", ["--literal-pathspecs", "add", "--", fileName], { cwd: repo });

const result = runReview(repo);
expect(result.status).toBe(0);
expect(result.stderr).toBe("");
expect(result.stdout).toContain(`CRITICAL ${fileName}:1`);
expect(result.stdout).not.toContain("No security issues found in staged changes.");

const normalRepo = createRepo("normal-pathspec-control");
writeFileSync(
join(normalRepo, "fixture.ts"),
`const token = "${syntheticGitHubToken}";\n`,
);
execFileSync("git", ["add", "--", "fixture.ts"], { cwd: normalRepo });

const normal = runReview(normalRepo);
expect(normal.status).toBe(0);
expect(normal.stderr).toBe("");
expect(normal.stdout).toContain("CRITICAL fixture.ts:1");

const safeRepo = createRepo("safe-pathspec-control");
writeFileSync(join(safeRepo, "fixture.ts"), "const safe = true;\n");
execFileSync("git", ["add", "--", "fixture.ts"], { cwd: safeRepo });

const safe = runReview(safeRepo);
expect(safe.status).toBe(0);
expect(safe.stderr).toBe("");
expect(safe.stdout).toContain("No security issues found in staged changes.");
});

test("scans the staged index content rather than later unstaged edits", () => {
const repo = createRepo("index-content");
writeFileSync(join(repo, "fixture.ts"), "const safe = true;\n");
Expand Down
11 changes: 10 additions & 1 deletion src/cli/commands/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ function safeStagedPath(filePath: string): string {
function addedLinesForFile(cwd: string, filePath: string): Set<number> {
const diff = execFileSync(
"git",
["diff", "--cached", "--unified=0", "--no-color", "--no-ext-diff", "--", filePath],
[
"--literal-pathspecs",
"diff",
"--cached",
"--unified=0",
"--no-color",
"--no-ext-diff",
"--",
filePath,
],
{ cwd, encoding: "utf-8" },
);
const addedLines = new Set<number>();
Expand Down
Loading