From 83b6c99b503dced1e92761e1de8ceaf23a396453 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Thu, 27 Feb 2014 12:41:28 -0600 Subject: [PATCH] Handle non-zero exit code from git diff The check for a changed repo in setup_develop() 'git diff --exit-code' returns a status of 1 when the repo has changes; trap that so errexit does not abort the script. Bug-Id: 1285780 Change-Id: Ic97e68348f46245b271567893b447fcedbd7bd6e --- functions-common | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/functions-common b/functions-common index 8e6b2b1895..0d85068a2f 100644 --- a/functions-common +++ b/functions-common @@ -1223,14 +1223,12 @@ function pip_install { function setup_develop() { local project_dir=$1 - echo "cd $REQUIREMENTS_DIR; $SUDO_CMD python update.py $project_dir" - # Don't update repo if local changes exist # Don't use buggy "git diff --quiet" - (cd $project_dir && git diff --exit-code >/dev/null) - local update_requirements=$? + # ``errexit`` requires us to trap the exit code when the repo is changed + local update_requirements=$(cd $project_dir && git diff --exit-code >/dev/null || echo "changed") - if [ $update_requirements -eq 0 ]; then + if [[ $update_requirements = "changed" ]]; then (cd $REQUIREMENTS_DIR; \ $SUDO_CMD python update.py $project_dir) fi @@ -1246,7 +1244,7 @@ function setup_develop() { # a variable that tells us whether or not we should UNDO the requirements # changes (this will be set to False in the OpenStack ci gate) if [ $UNDO_REQUIREMENTS = "True" ]; then - if [ $update_requirements -eq 0 ]; then + if [[ $update_requirements = "changed" ]]; then (cd $project_dir && git reset --hard) fi fi