Skip to content

Commit b5eba13

Browse files
committed
fix(patches): properly add new file to patch
1 parent b4be249 commit b5eba13

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/fileSystemProvider.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,28 @@ export class ElectronPatchFileSystemProvider extends ElectronFileSystemProvider
117117
cwd: vscode.Uri,
118118
newBlobId: string,
119119
) {
120+
const queryParams = new URLSearchParams(uri.query);
121+
120122
// Parse the existing patch file to get the metadata
121123
const patchContents = (
122124
await vscode.workspace.fs.readFile(patchFileUri)
123125
).toString();
124126
const { preamble, from, date, subject, description, files } =
125127
parsePatchMetadata(patchContents);
126128

129+
const relativeFilePath = path.relative(cwd.fsPath, uri.fsPath);
130+
131+
// If the file isn't already in the patch, add it as a new file
132+
if (!files.some((file) => file.filename === relativeFilePath)) {
133+
files.push({
134+
oldFilename: relativeFilePath,
135+
filename: relativeFilePath,
136+
blobIdA: queryParams.get("blobIdA") ?? "",
137+
blobIdB: "",
138+
});
139+
files.sort((a, b) => a.filename.localeCompare(b.filename));
140+
}
141+
127142
// Now reconstruct the whole patch file
128143
let newPatchContents = `${preamble}\nFrom: ${from}\nDate: ${date}\nSubject: ${subject}\n\n${description}\n\n`;
129144

0 commit comments

Comments
 (0)