Skip to content

fix(commit): use os.unlink to remove temp file #1396

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alxgu
Copy link

@alxgu alxgu commented Apr 29, 2025

NamedTemporaryFile doesn't have a unlink function when delete=False is used

Fix #1352

Description

Fix the traceback, when cz c --edit is used

Checklist

  • Add test cases to all the changes you introduce
  • Run poetry all locally to ensure this change passes linter check and test
  • Test the changes on the local machine manually
  • Update the documentation for the changes

Expected behavior

Save the commit message without an exception traceback.

Steps to Test This Pull Request

  1. Run cz commit -e
❯ cz c --edit
? Select the type of change you are committing fix: A bug fix. Correlates with PATCH in SemVer
? What is the scope of this change? (class or file name): (press [enter] to skip)
 test
? Write a short and imperative summary of the code changes: (lower case and no period)
 test
? Provide additional contextual information about the code changes: (press [enter] to skip)
 test
? Is this a BREAKING CHANGE? Correlates with MAJOR in SemVer No
? Footer. Information about Breaking Changes and reference issues that this commit closes: (press [enter] to skip)
 test
Traceback (most recent call last):
  File ".../commitizen/.venv/bin/cz", line 6, in <module>
    sys.exit(main())
  File "...//commitizen/commitizen/cli.py", line 656, in main
    args.func(conf, arguments)()
  File ".../commitizen/commitizen/commands/commit.py", line 130, in __call__
    m = self.manual_edit(m)
  File ".../commitizen/commitizen/commands/commit.py", line 92, in manual_edit
    file.unlink()
  File "/usr/lib/python3.10/tempfile.py", line 633, in __getattr__
    a = getattr(file, name)
AttributeError: '_io.TextIOWrapper' object has no attribute 'unlink'

Additional context

#1352

NamedTemporaryFile doesn't have a unlink function when delete=False is used

Fix commitizen-tools#1352
Copy link

codecov bot commented Apr 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.55%. Comparing base (120d514) to head (939bb03).
Report is 587 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1396      +/-   ##
==========================================
+ Coverage   97.33%   97.55%   +0.21%     
==========================================
  Files          42       57      +15     
  Lines        2104     2656     +552     
==========================================
+ Hits         2048     2591     +543     
- Misses         56       65       +9     
Flag Coverage Δ
unittests 97.55% <100.00%> (+0.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cz commit -e crashes on editor exit
2 participants