In Travis-ci I'm using this command.
git push origin HEAD:${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}
This all works perfectly fine unless there is nothing to commit (response: Everything up-to-date).
This is a perfectly fine response in my case, but it results in: exited with 1. This is something I would like to avoid. Regardless if it actually is able to commit or if all is up to date I would like the response to be exit 0.
How can I do this?
UPDATE:
As mentioned by @Mort in the comments, || true works, but now I always have a positive exit status. I would like to only change the Git exit code for Everything up-to-date.
Your question isn't unique to Travis, and with that in mind, this has already been answered on this page. But I will re-post my own version of the most popular (and best) answer there, here, as I don't have enough reputation to mark this as a duplicate.
So, you're having the classic exited with a 1 problem because you tried to commit when there was nothing to commit. But you still want it to exited with a 1 if there is an actual problem. Just do this: don't run the commit command at all if you find that there is nothing to commit. You will check beforehand if there are any commits to be had, like so:
git diff-index --quiet HEAD || git commit -am 'Jolly ol commit message'
It's pretty slick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With