Skip to content

Commit f7dfa1a

Browse files
committed
add docs
1 parent 5a87e21 commit f7dfa1a

5 files changed

Lines changed: 112 additions & 4 deletions

File tree

copier/_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def __init__(self, executable: PathLike[str]) -> None:
165165
resolve_commit_to_sha = cli.Flag(
166166
["--resolve-commit-to-sha"],
167167
default=False,
168-
help="Store SHA commit hash instead of git ref in answers file (prevents issues with moving tags)",
168+
help="Store SHA commit hash instead of git ref in answers file for immutable references",
169169
)
170170

171171
@cli.switch( # type: ignore[misc]

copier/_main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ class Worker:
219219
220220
resolve_commit_to_sha:
221221
When `True`, store SHA commit hash instead of git ref (tag/branch)
222-
in the answers file. This prevents issues with moving/floating tags
223-
that may point to different commits over time.
222+
in the answers file. This provides an immutable reference to the
223+
exact template version used.
224224
"""
225225

226226
# NOTE: attributes are fully documented in [creating.md](../docs/creating.md)
@@ -349,7 +349,7 @@ def _answers_to_remember(self) -> Mapping[str, Any]:
349349
should_resolve = self.template.resolve_commit_to_sha
350350

351351
if should_resolve and self.template.vcs == "git":
352-
# Use SHA hash instead of potentially moving ref
352+
# Use SHA hash for immutable reference
353353
commit = self.template.commit_hash or commit
354354
src = self.template.url
355355
for key, value in (("_commit", commit), ("_src_path", src)):

docs/configuring.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,58 @@ Suppress status output.
14421442

14431443
Not supported in `copier.yml`.
14441444

1445+
### `resolve_commit_to_sha`
1446+
1447+
- Format: `bool`
1448+
- CLI flags: `--resolve-commit-to-sha`
1449+
- Default value: `False`
1450+
1451+
When copying or updating from a Git-versioned template, store the actual SHA commit hash
1452+
in the answers file instead of the Git reference (tag/branch name). This provides an
1453+
immutable reference to the exact template version used, ensuring reproducibility and
1454+
traceability.
1455+
1456+
Storing SHA hashes instead of symbolic references (tags/branches) is useful for:
1457+
1458+
- **Reproducibility**: Ensures the exact same template version can be used across
1459+
different environments
1460+
- **Handling mutable references**: References that change over time (like floating
1461+
tags or branch heads) won't affect existing projects
1462+
1463+
!!! info
1464+
1465+
Template authors can enable this by default in their templates by setting
1466+
`_resolve_commit_to_sha: true` in `copier.yml`. The CLI flag takes precedence
1467+
over the template configuration.
1468+
1469+
!!! example "Usage examples"
1470+
1471+
```shell
1472+
# Store immutable reference for reproducible builds
1473+
copier copy --resolve-commit-to-sha --vcs-ref v2.0.0 template destination
1474+
1475+
# Working with a development branch
1476+
copier copy --resolve-commit-to-sha --vcs-ref main template destination
1477+
1478+
# Using a floating tag (stores the current SHA, not the tag)
1479+
copier copy --resolve-commit-to-sha --vcs-ref stable/latest template destination
1480+
```
1481+
1482+
In all cases, the answers file will contain a SHA hash like `a1b2c3d4e5f6`
1483+
instead of the symbolic reference, ensuring an immutable reference to the
1484+
exact template version.
1485+
1486+
!!! example "Template configuration"
1487+
1488+
Template authors can enable this behavior by default:
1489+
1490+
```yaml title="copier.yml"
1491+
_resolve_commit_to_sha: true
1492+
```
1493+
1494+
This ensures all projects generated from the template will store immutable
1495+
SHA references for better reproducibility and traceability.
1496+
14451497
### `secret_questions`
14461498

14471499
- Format: `List[str]`

docs/faq.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,55 @@ $ copier copy -r HEAD ./src ./dst
215215
... then you'll notice `new-file.txt` does exist. You passed a specific ref to copy, so
216216
Copier skips its autodetection and just goes for the `HEAD` you already chose.
217217

218+
## When should I use SHA references instead of tags/branches?
219+
220+
The `--resolve-commit-to-sha` flag stores the actual commit SHA instead of symbolic
221+
references (tags/branches) in your answers file. This is useful in several scenarios:
222+
223+
### For reproducible builds
224+
225+
When you need to ensure that everyone on your team or CI/CD pipeline uses the exact same
226+
template version:
227+
228+
```shell
229+
copier copy --resolve-commit-to-sha --vcs-ref v2.0.0 template destination
230+
```
231+
232+
### For audit and compliance
233+
234+
When you need immutable records of which exact template version was used for security or
235+
compliance purposes.
236+
237+
### When working with development branches
238+
239+
If you're using templates from frequently updated branches:
240+
241+
```shell
242+
copier copy --resolve-commit-to-sha --vcs-ref main template destination
243+
```
244+
245+
### With floating or moving tags
246+
247+
Some templates use floating tags (like `stable/v1` or `latest`) that get moved to newer
248+
commits:
249+
250+
```shell
251+
copier copy --resolve-commit-to-sha --vcs-ref stable/latest template destination
252+
```
253+
254+
### Template author configuration
255+
256+
Template authors can enable this behavior by default to ensure all projects use
257+
immutable references:
258+
259+
```yaml title="copier.yml"
260+
_resolve_commit_to_sha: true
261+
```
262+
263+
Using SHA references provides better reproducibility, traceability, and security, though
264+
at the cost of not automatically following tag updates. See [resolve_commit_to_sha][]
265+
for more details.
266+
218267
## How to pass credentials to Git?
219268

220269
If you do something like this, and the template supports updates, you'll notice that the

docs/updating.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ This will read all available Git tags, will compare them using
3636
before updating. To update to the latest commit, add `--vcs-ref=HEAD`. You can use any
3737
other Git ref you want.
3838

39+
!!! tip "Using immutable references for updates"
40+
41+
If your template uses references that may change over time (like floating tags or branch heads),
42+
consider using the `--resolve-commit-to-sha` flag when initially copying the template.
43+
This stores the actual commit SHA instead of the symbolic reference, ensuring reproducible
44+
updates with an immutable reference. See [resolve_commit_to_sha][] for more details.
45+
3946
When updating, Copier will do its best to respect your project evolution by using the
4047
answers you provided when copied last time. However, sometimes it's impossible for
4148
Copier to know what to do with a diff code hunk. In those cases, copier handles the

0 commit comments

Comments
 (0)