How to test outcome of git pull?

Viewed 262

I would like to test the outcome of git pull.

Currently we use this deployment approach:

git pull && rake build && rake deploy

However it unfortunately does much unnecessary work in the case that the pull is a no-op.

Can this be improved?

2 Answers

There's basically two things you can do. You can interpret the output, or you can interrogate to see if anything has changed.

You haven't specified your shell (windows or a unix shell like bash) so I can't give example code. But git pull will print Already up-to-date. if nothing changes. So skip the build and deploy if that happens.

The second option is to check your commit number before and after using:

git rev-list -n 1 HEAD

If this changes, then the pull did something, if not then it didn't

Use git log -1 --pretty=format:%H to get the commit hash before and after the git pull.

Compare both hashes and start a build when they differ.

Related