fix(cmd-version): handle committing of git-ignored file gracefully #764
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
Fix a TypeError when one of the modified files during
version
command adds a file that matches a.gitignore
pattern.Rationale
I personally don't commit a change to the version number in my files when building my distribution. To enable my software to know its version number I write it to a file that is imported
_version.py
. This file is generated by the build systemsetuptools_scm
and it makes it easy to have this file git-ignored. When semantic-release executed the update to the version file, it tried to add it to the index and git rejects with an exit code unless the--force
command is provided. My recommendation (this implementation) is to catch this error gracefully and print a warning to the developer in case they did not desire it to be ignored.How I tested
I modified the current testing infrastructure to instead of using
__init__.py
as the version holder to instead use_version.py
that can be our concept for an ignored file. I figured this helps the tests evenly hit more failure possibilities as we already have a filepyproject.toml
that is being committed with a version number change. This way we have one ignored and one committed for all tests.