How can I say when "hg push" failed (as opposed to "no change")

According to hg help push , he

Returns 0 if the click was successful, 1 if nothing was pressed.

Now I don’t have a beard, but it doesn’t look like the Unixy method.

for instance

 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 would like hg push to behave this way, especially since the information command hg out returns exactly the same status code.

So my question is: how can I say when hg push really failed? Should I read the stream output?

(By the way, someone pointed out in Janaruy 2012 that it does not work this way, and they fixed the program instead of the documentation.)

(I also know that set -e has problems . It's not about that.)

+4
source share
2 answers

As pointed out by @mamnotmaynard in the comments, hg push goes beyond 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 doesn't make sense to me, but go ahead.

+1
source

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[@]}" 
+2
source

Source: https://habr.com/ru/post/1499832/


All Articles