git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

Previous: Nick AndrewNext: Junio C Hamano
Message 5 of 8 in “Enable git rev-list to parse --quiet”
  1. Enable git rev-list to parse --quietNick Andrew, Jul 18, 2008
  2. Junio C HamanoJul 18, 2008
  3. Junio C HamanoJul 18, 2008
  4. Nick AndrewJul 18, 2008
  5. Johannes SchindelinJul 18, 2008
  6. Junio C HamanoJul 20, 2008
  7. Nick AndrewJul 20, 2008
  8. Junio C HamanoJul 20, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.