Problem
When running the codeguardian checks in a GitHub Actions CI environment, the job fails with the following error:
Error: fatal: ambiguous argument 'main...HEAD': unknown revision or path not in the working tree.
This breaks CI runs for projects that rely on GitHub-hosted runners and default checkout strategies.
Root Cause
- The CLI and npm scripts set
main as the default base branch for git comparisons (e.g., --base main or -b main).
- In a typical GitHub Actions workflow, the local clone does not guarantee the presence of the
main branch ref by default, especially if actions/checkout uses a shallow fetch (default fetch-depth: 1).
- As a result, any
git diff main...HEAD or similar operation fails in CI, even though it works locally.
Evidence
- Full error:
fatal: ambiguous argument 'main...HEAD': unknown revision or path not in the working tree.
- Scripts in
package.json enforce -b main by default.
Suggested Solutions
- Make the CLI and workflow scripts resolve the actual default branch robustly, not just assume
main exists.
- In CI, prefer to use
origin/<default branch> or allow an override based on the GitHub event context (github.event.pull_request.base.ref).
- Add fallback logic in the CLI for when
main isn't available as a local ref.
- Recommend in the README (and optionally in workflow examples) that users set
fetch-depth: 0 in actions/checkout or otherwise ensure the base branch is locally present.
Problem
When running the codeguardian checks in a GitHub Actions CI environment, the job fails with the following error:
This breaks CI runs for projects that rely on GitHub-hosted runners and default checkout strategies.
Root Cause
mainas the default base branch for git comparisons (e.g.,--base mainor-b main).mainbranch ref by default, especially ifactions/checkoutuses a shallow fetch (defaultfetch-depth: 1).git diff main...HEADor similar operation fails in CI, even though it works locally.Evidence
fatal: ambiguous argument 'main...HEAD': unknown revision or path not in the working tree.package.jsonenforce-b mainby default.Suggested Solutions
mainexists.origin/<default branch>or allow an override based on the GitHub event context (github.event.pull_request.base.ref).mainisn't available as a local ref.fetch-depth: 0inactions/checkoutor otherwise ensure the base branch is locally present.