nvie / gitflow

Git extensions to provide high-level repository operations for Vincent Driessen's branching model.
http://nvie.com/posts/a-successful-git-branching-model/
Other
26.6k stars 2.66k forks source link

[BUG] "Fatal" error of "Working tree contains unstaged changes" returns zero error code #6466

Closed ivan-iljin closed 3 years ago

ivan-iljin commented 3 years ago

Say i have some unstaged changes, and i run git flow release... On windows, here is my .bat script:

git flow release start %NEW_VERSION%
if not %ERRORLEVEL%==0 GOTO ERRORS
exit

:ERRORS
echo "ERRORS ENCOUNTERED! See output above."
exit

The condition works fine for other programs, the program stops on errors, and outputs the warning but not in case of git flow release ...

Actual: On fatal error "Working tree contains unstaged changes", git flow returns 0 from the process. Making it hard to catch errors in case of scripting the flow.

Expected: A fatal error like this should always return a non-zero code from the process.

ivan-iljin commented 3 years ago

Eh, turns out at the start of the script i had set ERRORLEVEL=0 And in this case cmd doesn't allow sub-processes to override that error level.

I've removed that line and now the return code 1 comes fine.

PS: I decided to look more into my code after i saw how die is defined here: https://github.com/nvie/gitflow/blob/15aab26490facf285acef56cb5d61025eacb3a69/gitflow-common

ivan-iljin commented 3 years ago

Even better, to reset old ERRORLEVEL, i'll use set ERRORLEVEL= This removes the value and allows sub-processes to set a new one.