Repository navigation
fix(unwip): do not undo a commit with an empty message - #1288
Merged
spacewander merged 1 commit intoNov 23, 2026
Merged
Conversation
$LAST_COMMIT was unquoted, so for a commit with an empty message the check became `[ 'WIP' != ]`. test then errors out with "unary operator expected", the if branch is skipped and `git undo --soft` drops a commit that is not a WIP commit. Quote the variable and add tests.
hyperupcall
approved these changes
Nov 20, 2026
hyperupcall
left a comment
Collaborator
There was a problem hiding this comment.
Thanks, surprised this wasn't caught earlier.
Collaborator
|
@shivangithaker-0510 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
git unwipshould only undo the last commit when its message isWIP.$LAST_COMMITis unquoted in the check, so a commit with an empty message makes ittestfails withunary operator expectedand returns non-zero. The "not a WIP commit" branch is skipped, and the script runsgit undo --softon a commit that is not a WIP commit:The fix quotes the variable. I also added
tests/git-unwip.bats: a WIP commit is undone, a normal commit is kept, and a commit with an empty message is kept. The last test fails without the fix.AI disclosure: I used an AI coding assistant to find this bug and draft the fix and tests. I reviewed the change and reproduced the bug myself, and I ran the new tests with and without the fix.