Skip to content

Commit 42b95a9

Browse files
afurmvincentkoc
authored andcommitted
fix(plugins): harden git ref checkout
1 parent e692f5c commit 42b95a9

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Docs: https://docs.openclaw.ai
8080
- Process execution: collapse case-insensitive duplicate child environment keys on Windows so caller-provided overrides such as `PATH` cannot be shadowed by host `Path`.
8181
- Browser CLI: request the existing `operator.admin` gateway scope explicitly for browser control commands, avoiding unnecessary scope-upgrade approval loops. Fixes #81555. (#81716) Thanks @joshavant.
8282
- CLI/plugins: route lazy plugin command-registration chatter to stderr only during JSON-output command registration, keeping plugin-backed `--json` stdout parseable without changing parse-only or pass-through `--json` behavior. Fixes #81535. (#81536) Thanks @ScientificProgrammer and @vincentkoc.
83+
- Plugins: treat git plugin install refs as refs instead of checkout flags, so option-like selectors fail checkout instead of silently installing the default branch. Fixes #79898. (#79901) Thanks @afurm and @vincentkoc.
8384
- Web: honor explicitly configured global `web_search` providers during provider ownership resolution while keeping sandboxed `web_fetch` limited to bundled providers.
8485
- Plugins/doctor: repair configured legacy npm declaration stubs by reinstalling their npm packages into the managed plugin root instead of loading workspace `node_modules`, and warn when discovery sees those stubs. Fixes #79632. Thanks @Dylanzhang1128 and @vincentkoc.
8586
- Channels: keep configured third-party channel plugins visible in `openclaw channels list` when their manifest declares `channels` but has not added `channelConfigs` metadata yet. Fixes #81334. (#81340) Thanks @AllynSheep and @vincentkoc.

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe("installPluginFromGitSpec", () => {
131131
const cloneArgv = commandArgvAt(0);
132132
expect(cloneArgv.slice(0, 3)).toEqual(["git", "clone", "https://github.com/acme/demo.git"]);
133133
expect(cloneArgv[3]).toContain("/repo");
134-
expect(commandArgvAt(1)).toEqual(["git", "checkout", "--detach", "v1.2.3"]);
134+
expect(commandArgvAt(1)).toEqual(["git", "switch", "--detach", "--", "v1.2.3"]);
135135
expect(commandArgvAt(3)).toEqual([
136136
"npm",
137137
"install",
@@ -252,6 +252,30 @@ describe("installPluginFromGitSpec", () => {
252252
expect(installPluginFromInstalledPackageDirMock).not.toHaveBeenCalled();
253253
});
254254

255+
it("separates requested refs from git options", async () => {
256+
runCommandWithTimeoutMock
257+
.mockResolvedValueOnce({ code: 0, stdout: "", stderr: "" })
258+
.mockResolvedValueOnce({
259+
code: 128,
260+
stdout: "",
261+
stderr: "fatal: invalid reference: --ignore-skip-worktree-bits",
262+
});
263+
264+
const result = await installPluginFromGitSpec({
265+
spec: "git:github.com/acme/demo@--ignore-skip-worktree-bits",
266+
});
267+
268+
expect(result.ok).toBe(false);
269+
expect(commandArgvAt(1)).toEqual([
270+
"git",
271+
"switch",
272+
"--detach",
273+
"--",
274+
"--ignore-skip-worktree-bits",
275+
]);
276+
expect(installPluginFromInstalledPackageDirMock).not.toHaveBeenCalled();
277+
});
278+
255279
it("keeps the existing managed repo when replacement install fails", async () => {
256280
const gitDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-git-install-preserve-"));
257281
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)