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 2 Answers
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
nosetestsFrom help set:
-e Exit immediately if a command exits with a non-zero status.
You could try the following.
#!/bin/bash
git checkout $1
nosetests || exit 1
git checkout master
git merge $1
git push
git checkout $1The || 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