简体   繁体   中英

How can I tell when `hg push` failed (as opposed to “no changes”)

According to hg help push , it

Returns 0 if push was successful, 1 if nothing to push.

Now, I don't have a beard, but this does not seem like the "Unixy" way.

For example

set -e
hg push -R ~/some-repo
# never get here if push aborts for any reason
# ...OR if some-repo has no changes
exit 0

I can't imagine why I'd want hg push to behave this way, especially since the informational command hg out returns exactly the same status code.

So my question is, how can I tell when hg push actually failed? Do I have to read the stream output?

(Incidentally, someone pointed out in Janaruy 2012 that it wasn't working this way, and they fixed the program instead of the documentation.)

(Also I know that set -e has issues . This is not about that.)

First example:

read -a ERREXITSAVE < <(shopt -o -p errexit)
set +o errexit

hg push -R "$repo"
[[ $? == [01] ]] || exit 1

"${ERREXITSAVE[@]}"

Second example:

read -a ERREXITSAVE < <(shopt -o -p errexit)
read -a LASTPIPESAVE < <(shopt -o -p lastpipe)

set +o errexit
set -o lastpipe

... | ( hg push -R "$repo"; [[ $? == [01] ]]; ) | ... || exit 1

"${ERREXITSAVE[@]}"
"${LASTPIPESAVE[@]}"

As @iamnotmaynard indicated in the comments, hg push exits with 255 for errors. So you can do something like this

set +e
hg push -R $repo
status=$?
set -e
if [[ ! "01" =~ $status ]]; then
    exit 1
fi

It still makes no sense to me, but moving on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM