Skip to content

Commit 265740c

Browse files
committed
ty codeql
1 parent 12eaf1d commit 265740c

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

packages/agent/src/worktree-manager.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { exec } from "node:child_process";
1+
import { exec, execFile } from "node:child_process";
22
import * as fs from "node:fs/promises";
33
import * as path from "node:path";
44
import { promisify } from "node:util";
55
import type { WorktreeInfo } from "./types.js";
66
import { Logger } from "./utils/logger.js";
77

88
const execAsync = promisify(exec);
9+
const execFileAsync = promisify(execFile);
910

1011
export interface WorktreeConfig {
1112
mainRepoPath: string;
@@ -503,9 +504,9 @@ export class WorktreeManager {
503504

504505
private async runGitCommand(command: string): Promise<string> {
505506
try {
506-
const { stdout } = await execAsync(
507-
`cd "${this.mainRepoPath}" && git ${command}`,
508-
);
507+
const { stdout } = await execAsync(`git ${command}`, {
508+
cwd: this.mainRepoPath,
509+
});
509510
return stdout.trim();
510511
} catch (error) {
511512
throw new Error(`Git command failed: ${command}\n${error}`);
@@ -659,8 +660,14 @@ export class WorktreeManager {
659660
this.logger.info("Deleting worktree", { worktreePath });
660661

661662
try {
662-
// First, try to remove the worktree via git
663-
await this.runGitCommand(`worktree remove "${worktreePath}" --force`);
663+
// First, try to remove the worktree via git using execFileAsync for safety
664+
await execFileAsync(
665+
"git",
666+
["worktree", "remove", worktreePath, "--force"],
667+
{
668+
cwd: this.mainRepoPath,
669+
},
670+
);
664671
this.logger.info("Worktree deleted successfully", { worktreePath });
665672
} catch (error) {
666673
this.logger.warn(
@@ -747,7 +754,8 @@ export class WorktreeManager {
747754
async isWorktree(repoPath: string): Promise<boolean> {
748755
try {
749756
const { stdout } = await execAsync(
750-
`cd "${repoPath}" && git rev-parse --is-inside-work-tree`,
757+
"git rev-parse --is-inside-work-tree",
758+
{ cwd: repoPath },
751759
);
752760
if (stdout.trim() !== "true") {
753761
return false;

0 commit comments

Comments
 (0)