Thread (4 messages) flat view 4 messages, 3 authors, 2016-06-15

Re: [PATCH] Enable git rev-list to parse --quiet

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:44:58

Hi,

On Fri, 18 Jul 2008, Nick Andrew wrote:
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help