Skip to content

fix git plugin ref checkout handling - #79901

Closed
afurm wants to merge 1 commit into
openclaw:mainfrom
afurm:af/harden-git-plugin-ref-checkout
Closed

afurm wants to merge 1 commit into
openclaw:mainfrom
afurm:af/harden-git-plugin-ref-checkout

Conversation

@afurm

@afurm afurm commented May 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: git: plugin installs passed explicit refs to git checkout --detach <ref>, letting option-like values be parsed as checkout flags.
  • Why it matters: an invalid option-like ref such as --ignore-skip-worktree-bits can return success from Git and leave the clone on the default branch, weakening the installer's ref-pinning semantics.
  • What changed: git plugin ref checkout now uses git switch --detach -- <ref> so the requested value is interpreted as a ref and rejected when invalid.
  • What did NOT change (scope boundary): npm, ClawHub, marketplace, local path, and archive plugin install flows are unchanged.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Real behavior proof (required for external PRs)

  • Behavior or issue addressed: git: plugin installs should fail invalid option-like refs instead of allowing Git to treat them as checkout flags and continue on the default branch.
  • Real environment tested: macOS 15 / Darwin arm64, source checkout with the installer fix applied, Node 22.22.0, pnpm workspace install with a temporary OPENCLAW_HOME and temporary local git plugin repository.
  • Exact steps or command run after this patch: OPENCLAW_HOME="$tmp/openclaw-home" pnpm openclaw plugins install "git:file://$tmp/plugin-repo@--ignore-skip-worktree-bits"
  • Evidence after fix (screenshot, recording, terminal capture, console output, redacted runtime log, linked artifact, or copied live output): copied terminal output:
Cloning <tmp>/plugin-repo...
failed to checkout --ignore-skip-worktree-bits <tmp>/plugin-repo: fatal: invalid reference: --ignore-skip-worktree-bits
exit=1
  • Observed result after fix: the install fails during ref checkout before dependency installation, package scan, or install metadata persistence.
  • What was not tested: full pnpm check:changed; the lane selector included core/coreTests, and no Testbox runner was available locally.
  • Before evidence (optional but encouraged): copied Git behavior before the patch:
$ git checkout --detach --ignore-skip-worktree-bits
HEAD is now at ef8dea3 init
$ echo $?
0

Root Cause (if applicable)

  • Root cause: the git plugin installer passed the user-supplied ref directly after git checkout --detach, so Git parsed leading-dash values as checkout options.
  • Missing detection / guardrail: the existing unit test asserted a normal ref checkout but did not cover option-like ref values.
  • Contributing context (if known): Git accepts at least some checkout flags in this position and can return success without checking out the requested ref.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: src/plugins/git-install.test.ts
  • Scenario the test should lock in: option-like requested refs are passed after -- to git switch --detach and do not reach plugin package install when checkout fails.
  • Why this is the smallest reliable guardrail: it locks the argv boundary where the bug happened without invoking real package-manager installs.
  • Existing test that already covers this (if any): N/A
  • If no new test is added, why not: N/A

User-visible / Behavior Changes

Invalid option-like git plugin refs now fail checkout instead of potentially installing the repository default branch.

Diagram (if applicable)

N/A

Security Impact (required)

  • New permissions/capabilities? (Yes/No): No
  • Secrets/tokens handling changed? (Yes/No): No
  • New/changed network calls? (Yes/No): No
  • Command/tool execution surface changed? (Yes/No): Yes
  • Data access scope changed? (Yes/No): No
  • If any Yes, explain risk + mitigation: the Git checkout command changes from checkout --detach <ref> to switch --detach -- <ref> so the command treats the supplied value as a ref instead of an option.

Repro + Verification

Environment

  • OS: macOS 15 / Darwin arm64
  • Runtime/container: Node 22.22.0, pnpm source checkout
  • Model/provider: N/A
  • Integration/channel (if any): plugin installer
  • Relevant config (redacted): temporary OPENCLAW_HOME

Steps

  1. Create a temporary local git repository with a minimal plugin package.
  2. Run OPENCLAW_HOME="$tmp/openclaw-home" pnpm openclaw plugins install "git:file://$tmp/plugin-repo@--ignore-skip-worktree-bits".
  3. Run pnpm test src/plugins/git-install.test.ts.

Expected

  • The option-like ref is rejected as an invalid reference before plugin install proceeds.

Actual

  • The patched installer fails checkout with fatal: invalid reference: --ignore-skip-worktree-bits and exits 1.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: targeted unit test, formatter check, diff whitespace check, and live CLI install against a temporary local git repository.
  • Edge cases checked: normal refs still use detached checkout semantics through the updated argv, and option-like refs are separated from Git options.
  • What you did not verify: full core changed gate, because the changed-lane selector requested broad core/coreTests lanes and no Testbox runner was available locally.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? (Yes/No): Yes
  • Config/env changes? (Yes/No): No
  • Migration needed? (Yes/No): No
  • If yes, exact upgrade steps: N/A

Risks and Mitigations

  • Risk: very old Git versions may lack git switch.
    • Mitigation: OpenClaw targets modern Node and current Git install flows; git switch has been available since Git 2.23 and is supported by current Git for Windows/macOS/Linux distributions.

@openclaw-barnacle openclaw-barnacle Bot added size: XS proof: supplied External PR includes structured after-fix real behavior proof. labels May 9, 2026
@afurm
afurm force-pushed the af/harden-git-plugin-ref-checkout branch from 9bbadb0 to 0404ae7 Compare May 9, 2026 17:39
@hclsys

This comment was marked as low quality.

@clawsweeper

clawsweeper Bot commented May 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

Summary
The PR changes git plugin ref checkout from git checkout --detach <ref> to git switch --detach -- <ref> and adds regression coverage for option-like refs.

Reproducibility: yes. for the root cause: current main passes refs to git checkout --detach <ref>, and a scratch Git repo reproduced the option-like value exiting successfully under checkout. I did not run the full OpenClaw CLI install on current main.

Real behavior proof
Sufficient (terminal): The PR body supplies after-fix terminal output from a real source checkout showing the invalid option-like ref fails before install proceeds.

Next step before merge
No repair lane action is needed; the PR has no actionable review finding and should continue through normal maintainer validation.

Security
Cleared: The diff narrows an existing git command parsing boundary without adding dependencies, secrets, network calls, or broader permissions.

Review details

Best possible solution:

Land this focused installer fix after normal validation, then let the linked issue at #79898 close as implemented.

Do we have a high-confidence way to reproduce the issue?

Yes for the root cause: current main passes refs to git checkout --detach <ref>, and a scratch Git repo reproduced the option-like value exiting successfully under checkout. I did not run the full OpenClaw CLI install on current main.

Is this the best way to solve the issue?

Yes; switching this single argv boundary to git switch --detach -- <ref> is the narrowest maintainable fix, and git checkout -h confirms checkout’s -- form is pathspec-oriented rather than the right ref separator here.

What I checked:

  • Current main still passes the ref as a checkout argument: installPluginFromGitSpec currently runs git checkout --detach with parsed.ref as the next argv element, so an option-like value can still be parsed by Git as a checkout flag. (src/plugins/git-install.ts:290, 4cfcc32ee315)
  • Git install refs are documented behavior: The plugin CLI docs support git:<repo>@<ref> and say the requested ref is checked out before install, so treating the selector only as a ref is existing contract rather than a new feature. Public docs: docs/cli/plugins.md. (docs/cli/plugins.md:152, 4cfcc32ee315)
  • Dependency behavior was live-checked: In a scratch Git repo with Git 2.53.0, git checkout --detach --ignore-skip-worktree-bits exited 0 and detached HEAD, while git switch --detach -- --ignore-skip-worktree-bits exited 128 with fatal: invalid reference.
  • PR patch targets the implicated argv boundary: The head patch changes the checkout argv to git switch --detach -- parsed.ref and adds a unit test asserting option-like refs are passed after -- and do not proceed to package install on checkout failure. (src/plugins/git-install.ts:287, 0404ae72e351)
  • Real behavior proof supplied in PR body: The PR body includes copied terminal output from a macOS source checkout showing openclaw plugins install git:file://...@--ignore-skip-worktree-bits failing at checkout with fatal: invalid reference and exit=1 after the patch. (0404ae72e351)
  • Linked issue tracks the same root cause: The PR uses closing syntax for [Bug]: git plugin refs can be parsed as checkout flags #79898, whose report describes the same option-like ref being parsed as a checkout flag.

Likely related people:

  • Peter Steinberger: The git plugin installer and its tests were added together in commit d1ff0b0, including the current git checkout --detach path; the central files have no older local history in this checkout. (role: introduced behavior; confidence: high; commits: d1ff0b0fc2ce; files: src/plugins/git-install.ts, src/plugins/git-install.test.ts)

Remaining risk / open question:

  • Full changed-gate proof is not included in the PR body; landing should still rely on the normal touched-surface CI/Testbox gate.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 4cfcc32ee315.

@vincentkoc

Copy link
Copy Markdown
Member

Thanks @afurm. I landed this on main here:

42b95a9

The landed change keeps the fix focused on the git plugin installer argv boundary: explicit refs now use git switch --detach -- <ref>, so option-like selectors are treated as refs and fail instead of being parsed as checkout flags.

Credit is preserved in the changelog for @afurm and @vincentkoc, and this will be included in the next release.

Verification:

No dependency pins, package manifests, lockfiles, workflow matrix, or release-branch backports were changed.

@vincentkoc vincentkoc closed this May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: git plugin refs can be parsed as checkout flags

3 participants