git gamble crashes when pre-commit prevents a commit
Description
In my repository wonderbird/textual-game-of-life I have configured pre-commit hooks to reformat the code before committing.
In the default setup, pre-commit will prevent a commit, if a hook changed the code. In this situation, git returns the error code 1. The changes made by the code author are staged, the changes made by pre-commit are not staged.
When git gamble encounters this scenario, it crashes.
Steps to reproduce
-
Clone the branch
git-gamble-prepare-crashfrom wonderbird/textual-game-of-life. This is agit gamble --redresult:git clone -b git-gamble-prepare-crash git@github.com:wonderbird/textual-game-of-life.git -
Setup the project as described in the README.md, i.e. install python requirements and the pre-commit hooks.
At this stage, pytest will show one red test. This is the state right after git gamble --red.
-
Cherry pick the changes of commit #ff243d64. This is the expected minimal feature implementation:
git cherry-pick --no-commit ff243d6 -
Run
pytest --snapshot-updateto update the expected screenshots for the snapshot tests. This will make the tests green -pytest -
Run
git gamble --green
Expected behavior
-
git gambleshould run the tests successfully - The
pre-commithooks should run successfully, potentially returning status code 1 when hooks have changed code -
git gambleshould present an appropriate error message instead of crashing
Actual behavior
-
git gambleruns the tests successfully - The
pre-commithooks execute and report that thetrim trailing whitespacehook has been executed. This is, because thesvgfiles end with a newline character. As a consequence thepre-commithook removes the trailing whitespace, prevents the git commit and git returns error code1. -
error: git gamble died of signal 6. The screen dump and the crash report below give more details
Workaround
In general, I assume that running git gamble once more after pre-commit has modified files might finally produce the commit.
However, in my particular situation, the snapshot tests will fail, because the modified svg images don't match the snapshots created during the test. Thus, in my project I should exclude the snapshot svgs from pre-commit.
You can reproduce my workaround by applying the changes from commit #c8da351e (note the exclusion rule in .pre-commit-config.yaml):
git restore --staged __snapshots__ game_app.py
git restore __snapshots__ game_app.py
rm __snapshots__/test_game_app/test_r_key_should_reset_to_seed.svg
git cherry-pick --no-commit c8da351e
git gamble --green
Crash report content
name = "git-gamble"
operating_system = "Mac OS 15.6.0 [64-bit]"
crate_version = "2.11.0"
explanation = """
Panic occurred in file 'src/bin/git-gamble.rs' at line 46
"""
cause = 'called `Result::unwrap()` on an `Err` value: Custom { kind: Other, error: "Failed to execute `git commit --allow-empty-message --reuse-message HEAD --no-edit --amend` in . returns code 1" }'
method = "Panic"
backtrace = """
0: 0x100811550 - __mh_execute_header
1: 0x1007faa20 - __mh_execute_header
2: 0x100866d20 - __mh_execute_header
3: 0x10086a79c - __mh_execute_header
4: 0x10086a70c - __mh_execute_header
5: 0x1008665e8 - __mh_execute_header
6: 0x10088d628 - __mh_execute_header
7: 0x10088d9f0 - __mh_execute_header
8: 0x1007fe308 - __mh_execute_header
"""
Environment
- Operating system : macOS Sequoia 15.6 (Apple M1 Max)
- Installed version (
git-gamble --version) :git-gamble 2.11.0 - Gamble test command :
pytest
Additional informations
Screen Dump
$ git gamble --green
===================================================== test session starts =====================================================
platform darwin -- Python 3.13.5, pytest-8.4.1, pluggy-1.6.0
rootdir: /Users/stefan/source/learning/textual-game-of-life
plugins: textual-snapshot-1.1.0, syrupy-4.8.0
collected 3 items
test_game_app.py ... [100%]
--------------------------------------------------- snapshot report summary ---------------------------------------------------
3 snapshots passed.
====================================================== 3 passed in 0.87s ======================================================
trim trailing whitespace.................................................Failed
- hook id: trailing-whitespace
- exit code: 1
- files were modified by this hook
Fixing __snapshots__/test_game_app/test_n_key_should_produce_next_generation.svg
Fixing __snapshots__/test_game_app/test_game_app.svg
Fixing __snapshots__/test_game_app/test_r_key_should_reset_to_seed.svg
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
black....................................................................Passed
Well, this is embarrassing.
git-gamble had a problem and crashed. To help us diagnose the problem you can send us a crash report.
We have generated a report file at "/var/folders/m5/dyhgw0bs0bd39k7rpcbys_lr0000gn/T/report-d238aa30-b8b6-4a79-aba2-aa43dbdcc7fc.toml". Submit an issue or email with the subject of "git-gamble Crash Report" and include the report as an attachment.
- Homepage: https://git-gamble.is-cool.dev
- Authors: pinage404 <pinage404+git-gamble@gmail.com>
To submit the crash report:
- Issue: https://gitlab.com/pinage404/git-gamble/-/issues/new
We take privacy seriously, and do not perform any automated error collection. In order to improve the software, we rely on people to submit reports.
Thank you kindly!
error: git-gamble died of signal 6