copier
copier copied to clipboard
ProcessExecutionError when a file is un-ignored across template versions
Describe the problem
In one tagged release of my copier template, I added an entry to a templated .gitignore to ignore the file .env. In a later tagged release, I removed this entry from the templated .gitignore file. Now, when upgrading templated projects, I get this error:
ProcessExecutionError: | Unexpected exit code: 1
Stderr: | The following paths are ignored by one of your .gitignore files:
| .env
Template
Currently must remain private. =/
To Reproduce
- Within the template, add an entry to the templated
.gitignore - Commit and tag the template repo.
- Update templated project(s).
- Within the template, remove the entry from the templated
.gitignore - Commit and tag the template repo.
- Update templated project(s) and observe the error.
Logs
ProcessExecutionError: | Unexpected exit code: 1
Stderr: | The following paths are ignored by one of your .gitignore files:
| .env
The stack trace points to the git add command here:
https://github.com/copier-org/copier/blob/v9.3.1/copier/main.py#L1002
Expected behavior
Copier should force-add the file and proceed without error.
Screenshots/screencasts/logs
No response
Operating system
macOS
Operating system distribution and version
Sonoma 14.6.1
Copier version
9.3.1
Python version
Python 3.12
Installation method
pipx+pypi
Additional context
The stack trace points to the git add command here:
https://github.com/copier-org/copier/blob/v9.3.1/copier/main.py#L1002
FWIW, git add has a flag -f, --force to "Allow adding otherwise ignored files".
As a workaround, the update completes successfully when I exclude the un-ignored file from the update: copier update --exclude .env
Thanks for reporting this problem, @fresh2dev! :+1:
You've traced the problem to its root, and I think adding the -f, --force flag to the git add command is correct. I'm just trying to better understand your scenario to write a meaningful test. Could you please provide a minimal reproducible example? Your reproduction steps are not complete, there must be a step where you add the file to be git-ignored for this problem to occur.
I created an example repo to reproduce the issue:
https://github.com/fresh2dev/copier-repro-1773
Looking at the commits on this example repo, the steps that cause this problem involve:
- init the repo
- later, add a file to a templated
.gitignore - later, remove a file from the templated
.gitignore
Here are the exact steps I followed to repro the issue from this repo:
- Create a new project from the initial template commit.
copier copy -r 1.0.0 https://github.com/fresh2dev/copier-repro-1773 hello-world
- Commit everything.
cd hello-world
git init
git add .
git commit -am 'init'
- Update the template to the next commit (this adds
.envto.gitignore) and commit.
copier update -fr 2.0.0
git commit -am 'update to v2'
- Update the template to the next commit (this removes
.envfrom.gitignore)
copier update -fr 3.0.0
- The errors out with
Stderr: | The following paths are ignored by one of your .gitignore files:
| .env
| hint: Use -f if you really want to add them.
| hint: Turn this message off by running
| hint: "git config advice.addIgnoredFile false"
This is resolved by PR https://github.com/copier-org/copier/pull/1886
The issue can be repro'd by executing the test case test_gitignore_file_unignored without the --force flag included in the git add command.
With the --force flag added, the test succeeds and no crash occurs.