Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cmd-version): handle committing of git-ignored file gracefully #764

Conversation

codejedi365
Copy link
Contributor

@codejedi365 codejedi365 commented Dec 7, 2023

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 system setuptools_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 file pyproject.toml that is being committed with a version number change. This way we have one ignored and one committed for all tests.

Tweaks tests to use one committed change file and the version file
as an ignored change file. This allows us to verify that our commit
mechanism does not crash if a file that is changed is ignored by user
Copy link
Contributor

@bernardcooke53 bernardcooke53 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 nice, I agree with you we get more mileage out of an ignored _version.py as well

@bernardcooke53 bernardcooke53 merged commit ea89fa7 into python-semantic-release:master Dec 12, 2023
8 checks passed
@codejedi365 codejedi365 deleted the fix/git-commit-ignored-file branch December 13, 2023 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants