Skip to content

Commit 0404ae7

Browse files
committed
fix: harden git plugin ref checkout
1 parent a8634e6 commit 0404ae7

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

‎src/plugins/git-install.test.ts‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ describe("installPluginFromGitSpec", () => {
103103
]);
104104
expect(runCommandWithTimeoutMock.mock.calls[1][0]).toEqual([
105105
"git",
106-
"checkout",
106+
"switch",
107107
"--detach",
108+
"--",
108109
"v1.2.3",
109110
]);
110111
expect(runCommandWithTimeoutMock.mock.calls[3][0]).toEqual([
@@ -225,6 +226,30 @@ describe("installPluginFromGitSpec", () => {
225226
expect(installPluginFromInstalledPackageDirMock).not.toHaveBeenCalled();
226227
});
227228

229+
it("separates requested refs from git options", async () => {
230+
runCommandWithTimeoutMock
231+
.mockResolvedValueOnce({ code: 0, stdout: "", stderr: "" })
232+
.mockResolvedValueOnce({
233+
code: 128,
234+
stdout: "",
235+
stderr: "fatal: invalid reference: --ignore-skip-worktree-bits",
236+
});
237+
238+
const result = await installPluginFromGitSpec({
239+
spec: "git:github.com/acme/demo@--ignore-skip-worktree-bits",
240+
});
241+
242+
expect(result.ok).toBe(false);
243+
expect(runCommandWithTimeoutMock.mock.calls[1][0]).toEqual([
244+
"git",
245+
"switch",
246+
"--detach",
247+
"--",
248+
"--ignore-skip-worktree-bits",
249+
]);
250+
expect(installPluginFromInstalledPackageDirMock).not.toHaveBeenCalled();
251+
});
252+
228253
it("keeps the existing managed repo when replacement install fails", async () => {
229254
const gitDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-git-install-preserve-"));
230255
const normalizedSpec = "git:https://github.com/acme/demo.git";

‎src/plugins/git-install.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export async function installPluginFromGitSpec(
287287

288288
if (parsed.ref) {
289289
const checkout = await runGitCommand({
290-
argv: ["git", "checkout", "--detach", parsed.ref],
290+
argv: ["git", "switch", "--detach", "--", parsed.ref],
291291
action: `checkout ${parsed.ref}`,
292292
source: parsed,
293293
cwd: repoDir,

0 commit comments

Comments
 (0)