fix(vcs): ignore empty nested git repos in dirty templates
Fixes #2692.
When copying from a dirty local template at HEAD, Copier clones the template into a temporary repository and creates an automatic WIP commit with the local dirty changes.
If the source tree contains a nested Git repository without a checked-out HEAD, git add -A fails with:
error: 'empty_repo/' does not have a commit checked out
fatal: adding files failed
This change detects nested Git repositories whose HEAD cannot be resolved and excludes them from the temporary WIP staging pathspec.
It also avoids creating the automatic dirty commit when no staged changes remain after those exclusions. This prevents a second Git failure when the only dirty item is an empty nested repository.
Regression coverage added for:
- a dirty local template containing only an empty nested Git repository, which should no longer crash;
- a dirty local template containing both an empty nested Git repository and a real dirty file, which should still include the dirty file and emit
DirtyLocalWarning.
Checks run:
pytest -q tests/test_dirty_local.py -k "empty_nested_git_repo or dirty_head" -rspytest -q tests/test_dirty_local.py tests/test_vcs.py -rsruff format --check copier/_vcs.py tests/test_dirty_local.pyruff check copier/_vcs.py tests/test_dirty_local.pygit diff --check
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 97.24%. Comparing base (5bec253) to head (683b720).
:warning: Report is 24 commits behind head on master.
Additional details and impacted files
@@ Coverage Diff @@
## master #2703 +/- ##
==========================================
+ Coverage 97.23% 97.24% +0.01%
==========================================
Files 60 60
Lines 7269 7305 +36
==========================================
+ Hits 7068 7104 +36
Misses 201 201
| Flag | Coverage Δ | |
|---|---|---|
| unittests | 97.24% <100.00%> (+0.01%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Harness.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
The only failing job is Windows 3.11, and it failed during astral-sh/setup-uv while fetching the uv manifest, before Python setup or tests started. All other matrix jobs passed, including the other Windows versions. This looks like an infra/setup failure rather than a code failure.