git-pull (or cg-fetch?) with exit status
Other than grep the output of the "pull" commands, I'd like to have a flag added that will also set an exit status to "successful" if new things were pulled. That way, I can automate a "make install" resulting from a successful new pull, ala:
git-pull --silent && make install
Signature · 4 lines
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[email protected]> <URL:http://www.stonehenge.com/merlyn/> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Quoted 6 lines · [email protected] (Randal L. Schwartz) writes:
Other than grep the output of the "pull" commands, I'd like to have a flag added that will also set an exit status to "successful" if new things were pulled. That way, I can automate a "make install" resulting from a successful new pull, ala:
git-pull --silent && make install
How about this instead of your one-liner?
old_head=$(git-rev-parse --verify HEAD) &&
git-pull -n >/dev/null 2>&1 || exit
new_head=$(git-rev-parse --verify HEAD)
test "$old_head" = "$new_head" || make test installgit-pull has at least 4 different possible outcomes, and its exit code talks about its success/failure right now.
1. fetch did not succeed, so pull should result in failure. In this case there is no change in your repository, and no point rebuilding.
2. fetch contacted the other end and concluded conversation correctly.
2-a. There was no change upstream (or you were up-to-date --
the other side was behind you). This is a successful pull, but you probably do not want to rebuild.
2-b. There were changes upstream and we tried to merge.
Merge was successful. This case you would want to rebuild.
2-c. There were changes upstream and automerge failed. You
cannot rebuild in this case.
With your proposal we should need to exit non-zero in case 2-a when we are running with --silent. This feels somewhat counter-intuitive if not wrong, even if it is only done under a particular flag.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Junio" == Junio C Hamano <[email protected]> writes:
Junio> old_head=$(git-rev-parse --verify HEAD) &&
Junio> git-pull -n >/dev/null 2>&1 || exit
Junio> new_head=$(git-rev-parse --verify HEAD)
Junio> test "$old_head" = "$new_head" || make test install
This looks like it might work. I'll try it out next time. Thanks.
Signature · 4 lines
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[email protected]> <URL:http://www.stonehenge.com/merlyn/> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!