Skip to content

fix(unwip): do not undo a commit with an empty message - #1288

Merged
spacewander merged 1 commit into
tj:mainfrom
shivangithaker-0510:fix/git-unwip-empty-message
Nov 23, 2026
Merged

spacewander merged 1 commit into
tj:mainfrom
shivangithaker-0510:fix/git-unwip-empty-message

Conversation

@shivangithaker-0510

Copy link
Copy Markdown
Contributor

git unwip should only undo the last commit when its message is WIP. $LAST_COMMIT is unquoted in the check, so a commit with an empty message makes it

if [ 'WIP' != ]; then

test fails with unary operator expected and returns non-zero. The "not a WIP commit" branch is skipped, and the script runs git undo --soft on a commit that is not a WIP commit:

git commit --allow-empty --allow-empty-message -m ""
git unwip
# git-unwip: line 9: [: WIP: unary operator expected
# (exit 0, the commit has been undone)

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.

$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 hyperupcall left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, surprised this wasn't caught earlier.

@spacewander
spacewander merged commit ad7a494 into tj:main Nov 23, 2026
5 checks passed
@spacewander

Copy link
Copy Markdown
Collaborator

@shivangithaker-0510
Merged. Thanks!

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.

3 participants