ghmerge: improve error handling
authorDr. Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Fri, 26 Jan 2018 09:33:22 +0000 (10:33 +0100)
committerRich Salz <rsalz@akamai.com>
Sat, 27 Jan 2018 15:57:16 +0000 (10:57 -0500)
commitc74b36e1cb2dec9183928b00a065131909c9412e
treeb2317b5c502fcacea76360ff09f4bc18b508f98c
parent9c2a1bcbb06f1075307267fe16bd34e43f750cd4
ghmerge: improve error handling

When python3 is the default python interpreter, the embedded script
fails with a syntax error at the print statement. In the absence of
error checking, this leads to a cascade of unhandled errors, ending
up in an empty pager window. Here an example:

  ghmerge prnum reviewer1 reviewer2

- the empty output of the python command causes the env command to print
  the (named and positional) parameters instead of clearing $1 and $2.
  Consequently, the script assigns WHO=reviewer1 and BRANCH=reviewer2.

- git checks out a local branch reviewer1-reviewer2 and tries to pull
  from https://github.com/reviewer1/openssl.git reviewer2
  This call fails, and again the error is ignored.

- The call `git diff reviewer1-reviewer2` leads to the empty pager
  window, since git has no diffs to show.

Countermeasures

- make the python script work for python2 and python3
- add a break-on-error statement (`set -o errexit`, aka `set -e`)
- replace `set` by `set --` which changes the behaviour of the set
  command as desired (see `man set`).
- add an explicit check for $WHO and $BRANCH
- add an exit trap for cleaning up the branch

Signed-off-by: Dr. Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
review-tools/ghmerge