Re: [PATCH] Enable git rev-list to parse --quiet
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Jul 18, 2008, 10:50 UTC
- Message-ID
- <alpine.DEB.1.00.0807181246590.3932@eeepc-johanness>
- In-Reply-To
- <20080718092001.GD16102@mail.local.tull.net>
Hi,
On Fri, 18 Jul 2008, Nick Andrew wrote:
Show 11 quoted lines
> I want to automatically (e.g. in crontab) update a git repo to the > latest HEAD from a remote branch ... but with the possibility that the > local repo has local changes, and I want no chance of merge failure. In > other words, "git fetch remote; git merge origin/master" and only do the > merge if it's a fast-forward. If there are any local commits, or local > uncommitted changes, then leave the local working tree alone. > > So my idea was to use "git rev-list --quiet master ^origin/master" and > check the exit code; if zero do "git merge origin/master". Without a > working "--quiet" nor exit code I can pipe the output to "wc -l" but is > there a more efficient/reliable way to implement the requirement?
Yes. Check if "$(git rev-parse master)" is different from "$(git rev-parse origin/master)" (to avoid unnecessary merging), and then that "$(git merge-base master origin/master)" is equal to "$(git rev-parse master)".
Note: this is plumbing, meant for scripting (which is exactly your scenario). Do not teach this to new Git users.
Ciao, Dscho