Melange provides two built-in pipelines for working with git repositories:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/chainguard-dev/melange/llms.txt
Use this file to discover all available pages before exploring further.
git-checkout for cloning and verifying source trees, and git-am for applying patch files using git am. Together they give you a reproducible, supply-chain-aware way to obtain upstream source code and incorporate security patches without modifying the upstream repository.
git-checkout
The git-checkout pipeline clones a remote git repository into the workspace. It supports shallow clones, branch and tag pinning, commit hash verification, submodule recursion, sparse checkout for monorepos, cherry-picks for CVE patches, and exponential-backoff retries for flaky network connections.
Inputs
| Input | Default | Required | Description |
|---|---|---|---|
repository | — | ✅ | URL of the repository to clone |
destination | . | — | Local path to clone into (relative to workspace) |
tag | — | — | Tag to check out. Mutually exclusive with branch. |
branch | — | — | Branch to check out. Mutually exclusive with tag. |
expected-commit | — | — | Expected commit SHA-1 hash. Fails the build if the resolved commit does not match. |
depth | unset (resolves to 1 for shallow clones; resolves to -1 when both branch and expected-commit are set) | — | Clone depth. Use -1 for full history. |
recurse-submodules | false | — | Pass --recurse-submodules to git clone |
shallow-submodules | false | — | Use --shallow-submodules when recursing (requires recurse-submodules: true) |
submodule-jobs | 1 | — | Concurrent jobs for submodule cloning |
cherry-picks | — | — | Newline-separated list of cherry-picks to apply after checkout |
sparse-paths | — | — | Directories to check out in sparse (cone-mode) checkout |
type-hint | — | — | Source type hint for SBOM generation (e.g. gitlab) |
max-retries | 3 | — | Maximum clone retry attempts |
initial-backoff | 2 | — | Initial backoff in seconds before first retry |
max-backoff | 60 | — | Maximum backoff in seconds between retries |
reason | — | — | Human-readable reason for using a mutable reference |
Basic usage
The most common pattern pins to a release tag and verifies the expected commit hash:Checking out different references
Theexamples/git-checkout.yaml file demonstrates several reference styles in a single build:
When an annotated tag is used,
expected-commit can be set to either the tag object hash or the underlying commit hash. If the tag object hash is provided, melange emits a warning recommending that you update to the commit hash, but the build succeeds.Cherry-picking commits for CVE patches
Thecherry-picks input lets you apply specific upstream commits on top of a checked-out tag. This is the recommended way to backport security fixes to a stable release without changing the base tag.
Each entry in the cherry-picks list has the format:
git cherry-pick may fail because the commit is not reachable from the shallow clone. The comment after : is required and serves as documentation.
Example — patching CPython for CVE-2024-4032:
3.10 from origin, then cherry-picks commit c62c9e518b784fe44432a3f4fc265fb95b651906 on top of the checked-out tag.
Submodules
For repositories with submodules, enable recursive cloning:Sparse checkout for monorepos
When working with large monorepos, usesparse-paths to check out only the directories you need. The pipeline uses cone-mode sparse checkout for optimal performance:
git-am
The git-am pipeline applies patch files to the checked-out repository using git am. It is an alternative to the patch pipeline that preserves git history for the applied patches.
Inputs
| Input | Default | Required | Description |
|---|---|---|---|
patches | — | ✅ | Whitespace-delimited list of patch file paths |
--source-dir (defaulting to the directory containing the melange YAML file). This assumes git-checkout cloned into the default destination (.).
Example
Place patch files in your package’s source directory alongside the melange YAML file. Melange copies that directory into the workspace root before the pipeline runs, making them available at the paths you specify in
patches:.Supply-chain integrity with expected-commit
Using expected-commit in combination with a tag provides two layers of verification:
- Tag integrity — confirms that the tag still resolves to the expected commit (guards against force-pushed tags).
- Annotated tag support — for annotated tags, either the tag object hash or the underlying commit hash is accepted. Melange warns when the tag object hash is used and recommends switching to the commit hash for stricter verification.
depth: -1 alongside expected-commit to allow melange to reset to the expected commit when the branch tip has moved:
