fix(git): discard repository paths from the worktree root

This commit is contained in:
见安
2026-10-13 10:24:58 +08:00
parent b0f054de90
commit 4948a96946
+6 -6
View File
@@ -3556,13 +3556,13 @@ export async function commitAll(cwd: string, message: string): Promise<void> {
}
export async function discardChanges(cwd: string, pathspecs: string[]): Promise<void> {
await requireGitRepo(cwd);
const worktreeRoot = await requireGitWorktreeRoot(cwd);
if (pathspecs.length === 0) {
return;
}
try {
await runGitCommand(["--literal-pathspecs", "reset", "-q", "HEAD", "--", ...pathspecs], {
cwd,
cwd: worktreeRoot,
timeout: DISCARD_CHANGES_TIMEOUT_MS,
});
} catch {
@@ -3570,7 +3570,7 @@ export async function discardChanges(cwd: string, pathspecs: string[]): Promise<
await runGitCommand(
["--literal-pathspecs", "rm", "--cached", "-r", "-q", "--ignore-unmatch", "--", ...pathspecs],
{
cwd,
cwd: worktreeRoot,
timeout: DISCARD_CHANGES_TIMEOUT_MS,
},
);
@@ -3582,7 +3582,7 @@ export async function discardChanges(cwd: string, pathspecs: string[]): Promise<
const status = await runGitCommand(
["--literal-pathspecs", "status", "--porcelain=v1", "-z", "--", ...pathspecs],
{
cwd,
cwd: worktreeRoot,
timeout: DISCARD_CHANGES_TIMEOUT_MS,
},
);
@@ -3608,13 +3608,13 @@ export async function discardChanges(cwd: string, pathspecs: string[]): Promise<
}
if (tracked.length > 0) {
await runGitCommand(["--literal-pathspecs", "checkout", "-q", "--", ...tracked], {
cwd,
cwd: worktreeRoot,
timeout: DISCARD_CHANGES_TIMEOUT_MS,
});
}
if (untracked.length > 0) {
await runGitCommand(["--literal-pathspecs", "clean", "-fd", "-q", "--", ...untracked], {
cwd,
cwd: worktreeRoot,
timeout: DISCARD_CHANGES_TIMEOUT_MS,
});
}