version-bump-prompt
version-bump-prompt copied to clipboard
Leave as-is crashes - exit code 1
When choosing an existing version (leave as-is in the menu) the app crashes as Git fails to commit without any changes:
$ bump prompt --commit --tag --push --preid r
?
The current version in package.json is 0.2.0
How would you like to bump it? leave as-is (0.2.0)
ℹ package.json did not need to be updated
ℹ package-lock.json did not need to be updated
git commit --message "release v0.2.0" exited with a status of 1.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] bump: `bump prompt --commit --tag --push --preid r`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] bump script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/x/.npm/_logs/2019-11-15T11_33_15_429Z-debug.log
ERROR: "bump" exited with 1.
In this case, version 0.2.0 has already been released and I simply wanted to leave the version as-is during deployment to another location.
Suggested fix: If a user selects leave-as-is, all other operations should be bypassed (git etc.) - Maybe process.exit(0)?
Seems that this is still an issue:

I believe it's caused by the lack of checking which choice was made when selecting a version, as processing just continues here: https://github.com/JS-DevTools/version-bump-prompt/blob/19cce02575867c9173ed8314e53f1425747934b8/src/version-bump.ts#L61-L68
The versioning choice should be checked, and operations like git etc. should be skipped, in my opinion. Of course leave-as-is will always have such an issue with git as tags will always exist.. so the only option I believe is to skip these calls.
The "leave as is" option was added because some people wanted Version Bump Prompt to do all the other stuff that it normally does (update other files, git commit, tag, push, etc.) even if the version number didn't change. That's why none of that stuff gets skipped when "leave as is" is selected.
I think the right workaround here is to add code to run "git status" first before running "git commit". If "git status" indicates that there are no changed files, then "git commit" would be skipped.
Also good to check if the current commit is tagged, perhaps git describe --exact-match HEAD helps here. But perhaps this can be entirely avoided by checking the commit status, as you mentioned.