6

I am using a small script to merge current branch into the trunk and push it out. How can I make the script fail if nosetests fails?

#!/bin/bash
git checkout $1
nosetests
git checkout master
git merge $1
git push
git checkout $1
7

Add set -e after the shebang line to make the script exit if any of the command fails:

#!/bin/bash
set -e
git checkout $1
nosetests

From help set:

-e Exit immediately if a command exits with a non-zero status.

3

You could try the following.

#!/bin/bash
git checkout $1
nosetests || exit 1
git checkout master
git merge $1
git push
git checkout $1

The || will check the return code of nosetests and will execute the command exit 1 if it is non-zero.

Another variant could be.

#!/bin/bash
git checkout $1
if ! nosetests
then
    exit 1
fi
git checkout master
git merge $1
git push
git checkout $1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.