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
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ async function runCommand(): Promise<void> {
const optimized = optimizeDiff(staged.diff, settings.maxDiffChars);
if (optimized.includedFiles.length === 0) {
vscode.window.showWarningMessage(
`Nuvo Commit: all ${useWorkingDir ? "unstaged" : "staged"} files are ignored (lock/generated/binary).`,
`Nuvo Commit: all ${useWorkingDir ? "unstaged" : "staged"} files are ignored (lock/generated).`,
);
return;
}
Expand Down Expand Up @@ -517,7 +517,7 @@ async function runPullRequestContentCommand(): Promise<void> {
const optimized = optimizeDiff(pullRequestDiff.diff, settings.maxDiffChars);
if (optimized.includedFiles.length === 0) {
vscode.window.showWarningMessage(
"Nuvo Commit: all pull request files are ignored (lock/generated/binary).",
"Nuvo Commit: all pull request files are ignored (lock/generated).",
);
return;
}
Expand Down
16 changes: 16 additions & 0 deletions src/utils/optimizeDiff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,19 @@ describe("optimizeDiff", () => {
expect(result.diff.length).toBeLessThanOrEqual(300);
});
});

describe("optimizeDiff binary files", () => {
it("keeps binary hunks so media-only commits can be described", () => {
const diff = [
"diff --git a/images/logo.png b/images/logo.png",
"new file mode 100644",
"index 0000000..abc1234",
"Binary files /dev/null and b/images/logo.png differ",
].join("\n");
const result = optimizeDiff(diff, 10_000);
expect(result.includedFiles).toEqual(["images/logo.png"]);
expect(result.diff).toContain(
"Binary files /dev/null and b/images/logo.png differ",
);
});
});
9 changes: 4 additions & 5 deletions src/utils/optimizeDiff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export function isIgnoredPath(path: string): boolean {
interface FileHunk {
path: string;
body: string;
binary: boolean;
}

interface KeptHunk extends FileHunk {
Expand All @@ -58,9 +57,7 @@ function parseHunks(diff: string): FileHunk[] {

const headerMatch = part.match(/^a\/(.+?) b\/(.+?)(?:\n|$)/);
const path = headerMatch ? headerMatch[2] : "unknown";
const binary = /^Binary files .* differ$/m.test(part);

hunks.push({ path, body, binary });
hunks.push({ path, body });
}

return hunks;
Expand All @@ -81,7 +78,9 @@ export function optimizeDiff(diff: string, maxChars: number): OptimizeResult {
const kept: KeptHunk[] = [];

for (const hunk of hunks) {
if (hunk.binary || isIgnoredPath(hunk.path)) {
// ponytail: binary hunks are header-only (no --binary), so they stay; the
// path + "new file mode" is enough for the model to name media-only commits.
if (isIgnoredPath(hunk.path)) {
skippedFiles.push(hunk.path);
continue;
}
Expand Down
Loading