Skip to content

Commit c061fd3

Browse files
committed
use execFileAsync
1 parent 9c153b1 commit c061fd3

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

apps/array/src/main/services/git.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type ChildProcess, exec } from "node:child_process";
1+
import { type ChildProcess, exec, execFile } from "node:child_process";
22
import fs from "node:fs";
33
import os from "node:os";
44
import path from "node:path";
@@ -10,6 +10,7 @@ import { logger } from "../lib/logger";
1010
const log = logger.scope("git");
1111

1212
const execAsync = promisify(exec);
13+
const execFileAsync = promisify(execFile);
1314
const fsPromises = fs.promises;
1415

1516
const getAllFilesInDirectory = async (
@@ -297,23 +298,23 @@ const discardFileChanges = async (
297298
switch (fileStatus) {
298299
case "modified":
299300
case "deleted":
300-
await execAsync(`git checkout HEAD -- "${filePath}"`, {
301+
await execFileAsync("git", ["checkout", "HEAD", "--", filePath], {
301302
cwd: directoryPath,
302303
});
303304
break;
304305
case "added":
305-
await execAsync(`git rm -f "${filePath}"`, {
306+
await execFileAsync("git", ["rm", "-f", filePath], {
306307
cwd: directoryPath,
307308
});
308309
break;
309310
case "untracked":
310-
await execAsync(`git clean -f -- "${filePath}"`, {
311+
await execFileAsync("git", ["clean", "-f", "--", filePath], {
311312
cwd: directoryPath,
312313
});
313314
break;
314315
case "renamed":
315316
// TODO: Restore the original file?
316-
await execAsync(`git checkout HEAD -- "${filePath}"`, {
317+
await execFileAsync("git", ["checkout", "HEAD", "--", filePath], {
317318
cwd: directoryPath,
318319
});
319320
break;

apps/array/src/renderer/features/task-detail/components/ChangesPanel.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,17 @@ function ChangedFileItem({
125125

126126
if (result.response !== 1) return;
127127

128-
try {
129-
await window.electronAPI.discardFileChanges(
130-
repoPath,
131-
file.path,
132-
file.status,
133-
);
134-
135-
closeDiffTabsForFile(taskId, file.path);
136-
137-
queryClient.invalidateQueries({
138-
queryKey: ["changed-files-head", repoPath],
139-
});
140-
} catch (_error) {}
128+
await window.electronAPI.discardFileChanges(
129+
repoPath,
130+
file.path,
131+
file.status,
132+
);
133+
134+
closeDiffTabsForFile(taskId, file.path);
135+
136+
queryClient.invalidateQueries({
137+
queryKey: ["changed-files-head", repoPath],
138+
});
141139
};
142140

143141
return (

0 commit comments

Comments
 (0)