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

Re: How can I tell if anything was fetched?

From
Jeff King <peff@peff.net>
Date
Oct 12, 2012, 07:47 UTC
Message-ID
<20121012074739.GD17026@sigill.intra.peff.net>
In-Reply-To
<m28vbdkley.fsf@igel.home>
On Thu, Oct 11, 2012 at 06:45:09PM +0200, Andreas Schwab wrote:
Show 16 quoted lines
> Phil Lawrence <prlawrence@gmail.com> writes:
> 
> > One approach might be to first generate a state-of-the-repo SHA1:
> >     # http://stackoverflow.com/a/7350019/834039
> >     # http://git-scm.com/book/ch9-2.html
> >     {
> >         git rev-list --objects --all
> >         git rev-list --objects -g --no-walk --all
> >         git rev-list --objects --no-walk \
> >             $(git fsck --unreachable |
> >               grep '^unreachable commit' |
> >               cut -d' ' -f3)
> >     } | sort | uniq | git hash-object -w --stdin
> 
> I think you'd only need to record the state of all refs (eg. the output
> of `git for-each-ref') to reliably detect any changes.

To clarify on the "only" in your sentence: it is not just that recording the ref changes is more efficient. But recording the object state is actively wrong. You might have fetched ref changes that do not introduce new objects (e.g., a rewind of history, or a branch deletion). The before-and-after ref state is both sufficient and necessary. I suspect you already realized that, Andreas, but I wanted to make sure it was clear to readers, including the OP.

Checking ref state does suffer from potential race conditions with any other simultaneous updates. I don't think there is any reason we couldn't have "git fetch" produce a machine-readable output detailing what happened. We already have the same for "git push". I think it is simply the case that nobody has really wanted it so far.

-Peff
Previous: Enrico WeigeltNext: Johannes Sixt
Message 4 of 5 in “How can I tell if anything was fetched?”
  1. Phil LawrenceOct 11, 2012
  2. Andreas SchwabOct 11, 2012
  3. Enrico WeigeltOct 11, 2012
  4. Jeff KingOct 12, 2012
  5. Johannes SixtOct 12, 2012

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.