{"thread":{"id":"31788","subject":"How can I tell if anything was fetched?","startedAt":"2012-10-11T16:25:23Z","lastAt":"2012-10-12T07:47:39Z","messageCount":5,"participants":["Phil Lawrence","Andreas Schwab","Enrico Weigelt","Johannes Sixt","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"200994","messageId":"CAFRB3XkueafikCvwzBb+WOAG_1mEkVg1Yt6=teOuVwYd2zWVOw@mail.gmail.com","threadId":"31788","inReplyTo":null,"subject":"How can I tell if anything was fetched?","fromName":"Phil Lawrence","fromEmail":"prlawrence@gmail.com","sentAt":"2012-10-11T16:25:23Z","receivedAt":"2012-10-11T16:25:23Z","isPatch":false,"sender":{"key":"prlawrence@gmail.com","avatar":"https://gravatar.com/avatar/352044d06dd8919a32522c18c712e0a8d07b8e8719c820b4b50ffb8f6f2fa1f0?d=mp&s=160"},"body":"I have a cron job that regularly fetches into a bare repo.  Currently,\nthe job then pushes the repo to another remote, regardless of whether\nor not anything was actually fetched.  That's a waste.\n\nWhat is the best way to know whether or not anything was received\nduring the fetch?  I don't want to be stuck trying to parse the answer\nout of STDOUT and STDERR...\n\nOne approach might be to first generate a state-of-the-repo SHA1:\n    # http://stackoverflow.com/a/7350019/834039\n    # http://git-scm.com/book/ch9-2.html\n    {\n        git rev-list --objects --all\n        git rev-list --objects -g --no-walk --all\n        git rev-list --objects --no-walk \\\n            $(git fsck --unreachable |\n              grep '^unreachable commit' |\n              cut -d' ' -f3)\n    } | sort | uniq | git hash-object -w --stdin\n\nI could then do the git fetch, generate another state-of-the-repo SHA1\nand compare...\n\nThoughts?\n\n--\nPhil Lawrence\n"},{"id":"200996","messageId":"m28vbdkley.fsf@igel.home","threadId":"31788","inReplyTo":"CAFRB3XkueafikCvwzBb+WOAG_1mEkVg1Yt6=teOuVwYd2zWVOw@mail.gmail.com","subject":"Re: How can I tell if anything was fetched?","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2012-10-11T16:45:09Z","receivedAt":"2012-10-11T16:45:09Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"Phil Lawrence <prlawrence@gmail.com> writes:\n\n> One approach might be to first generate a state-of-the-repo SHA1:\n>     # http://stackoverflow.com/a/7350019/834039\n>     # http://git-scm.com/book/ch9-2.html\n>     {\n>         git rev-list --objects --all\n>         git rev-list --objects -g --no-walk --all\n>         git rev-list --objects --no-walk \\\n>             $(git fsck --unreachable |\n>               grep '^unreachable commit' |\n>               cut -d' ' -f3)\n>     } | sort | uniq | git hash-object -w --stdin\n\nI think you'd only need to record the state of all refs (eg. the output\nof `git for-each-ref') to reliably detect any changes.\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5\n\"And now for something completely different.\"\n"},{"id":"201011","messageId":"369f3feb-20e5-444f-b718-15d7dc8f2c61@zcs","threadId":"31788","inReplyTo":"m28vbdkley.fsf@igel.home","subject":"Re: How can I tell if anything was fetched?","fromName":"Enrico Weigelt","fromEmail":"enrico.weigelt@vnc.biz","sentAt":"2012-10-11T18:29:05Z","receivedAt":"2012-10-11T18:29:05Z","isPatch":false,"sender":{"key":"enrico.weigelt@vnc.biz","avatar":"https://gravatar.com/avatar/15479654ea5be5109582e0713a8ab4bb258846099c516dd320dc686ef70a8a3e?d=mp&s=160"},"body":"\n> I think you'd only need to record the state of all refs (eg. the\n> output\n> of `git for-each-ref') to reliably detect any changes.\n\nI would just record the output of `git ls-remote . | sort -u` somewhere\nand compare it next time (maybe you even wanna grep for the desired\nref namespaces).\n\n\ncu\n-- \nMit freundlichen Grüßen / Kind regards \n\nEnrico Weigelt \nVNC - Virtual Network Consult GmbH \nHead Of Development \n\nPariser Platz 4a, D-10117 Berlin\nTel.: +49 (30) 3464615-20\nFax: +49 (30) 3464615-59\n\nenrico.weigelt@vnc.biz; www.vnc.de \n"},{"id":"201040","messageId":"5077B88E.5060303@viscovery.net","threadId":"31788","inReplyTo":"CAFRB3XkueafikCvwzBb+WOAG_1mEkVg1Yt6=teOuVwYd2zWVOw@mail.gmail.com","subject":"Re: How can I tell if anything was fetched?","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2012-10-12T06:28:30Z","receivedAt":"2012-10-12T06:28:30Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 10/11/2012 18:25, schrieb Phil Lawrence:\n> What is the best way to know whether or not anything was received\n> during the fetch?  I don't want to be stuck trying to parse the answer\n> out of STDOUT and STDERR...\n\nwhat=\"--all\"\t # or \"--remotes=the-remote\"\npresha1s=$(git rev-parse $what)\ngit fetch the-remote\nif test -z \"$(git rev-list -1 $what --not $presha1s)\"\nthen\n\techo nothing new\nfi\n\nError checking is left as an exercise for the user ;)\n\n-- Hannes\n"},{"id":"201048","messageId":"20121012074739.GD17026@sigill.intra.peff.net","threadId":"31788","inReplyTo":"m28vbdkley.fsf@igel.home","subject":"Re: How can I tell if anything was fetched?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2012-10-12T07:47:39Z","receivedAt":"2012-10-12T07:47:39Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Oct 11, 2012 at 06:45:09PM +0200, Andreas Schwab wrote:\n\n> Phil Lawrence <prlawrence@gmail.com> writes:\n> \n> > One approach might be to first generate a state-of-the-repo SHA1:\n> >     # http://stackoverflow.com/a/7350019/834039\n> >     # http://git-scm.com/book/ch9-2.html\n> >     {\n> >         git rev-list --objects --all\n> >         git rev-list --objects -g --no-walk --all\n> >         git rev-list --objects --no-walk \\\n> >             $(git fsck --unreachable |\n> >               grep '^unreachable commit' |\n> >               cut -d' ' -f3)\n> >     } | sort | uniq | git hash-object -w --stdin\n> \n> I think you'd only need to record the state of all refs (eg. the output\n> of `git for-each-ref') to reliably detect any changes.\n\nTo clarify on the \"only\" in your sentence: it is not just that recording\nthe ref changes is more efficient. But recording the object state is\nactively wrong. You might have fetched ref changes that do not introduce\nnew objects (e.g., a rewind of history, or a branch deletion). The\nbefore-and-after ref state is both sufficient and necessary.  I suspect\nyou already realized that, Andreas, but I wanted to make sure it was\nclear to readers, including the OP.\n\nChecking ref state does suffer from potential race conditions with any\nother simultaneous updates.  I don't think there is any reason we\ncouldn't have \"git fetch\" produce a machine-readable output detailing\nwhat happened. We already have the same for \"git push\". I think it is\nsimply the case that nobody has really wanted it so far.\n\n-Peff\n"}]}