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

Re: Sample pre-push hook can crash

From
Stephen Morton <stephen.c.morton@gmail.com>
Date
Mar 11, 2016, 20:35 UTC
Message-ID
<CAH8BJxGeSL24v=RxBG4oBXQcavrpuawm1_N0kR7QBYOkYjpXaQ@mail.gmail.com>
In-Reply-To
<xmqqmvq4aihh.fsf@gitster.mtv.corp.google.com>

Thanks for the information Junio. It is just interesting that although the pre-push hook receives the remote_sha value from the server, it does not get 'git merge-base $remote_sha $local_sha' which is what a check that iterated over all outgoing commits would really need. (I'm sure this is a simple-minded assessment. I don't pretend to have spent even an order of magnitude less time working on git than you have. I'm not trying to be foolishly arrogant.)

I do think it would be worth replacing the existing example with yours because the existing example will crash anytime somebody's workspace is up to date.

Stephen
On Fri, Mar 11, 2016 at 3:04 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 71 quoted lines
> Stephen Morton <stephen.c.morton@gmail.com> writes:
>
>> That is interesting, so in the case of a non-ff push, there is no way
>> for a pre-push hook to know what is being pushed in order to run?
>
> If you were up-to-date from the other side once:
>
>     ---A---B---C
>
> and built one new commit on top:
>
>     ---A---B---C---D
>
> when you attempt to push it out, there are various possibilities.
>
> An ff situation is simple.  They didn't do anything, so the hook
> gets "we'd be updating their ref from C to D", and "rev-list C..D"
> would tell you that you would need to make sure D is sane.
>
> If your push does not fast-forward, that would mean something has
> happened on the other side while you were working on D.  Perhaps
> they accepted another commit that you haven't seen:
>
>     ---A---B---C---E
>
> and because you haven't fetched from them, even though the hook may
> say "we'd be updating their ref from E to D", you haven't heard of
> E, you do not know where it would be relative to the history you
> have:
>
>                   E???
>
>     ---A---B---C---D
>
> Or perhaps they themselves rewound their history and they now have
> this E at the tip:
>
>     ---A---B---C
>             \
>              E
>
> But again, because you do not yet know where E is relative to your
> history, you cannot say C is where you can stop checking your side
> of the history.
>
> Or perhaps they somehow obtained your D without you pushing into
> them (e.g. you pushed to the "next" tree and they fixed your commit
> and the result was merged there) and have something like this:
>
>     ---A---B---C---D---E
>
> In this case, D is not even a new commit from their point of view,
> and updating their tip E with your old D would lose the fixup E they
> made for D, but again, you do not know what E is yet, you cannot say
> "they have this already, so there is no check I need to do".
>
> In summary, you cannot even say which ones you have need to be
> checked.
>
> If you _are_ using @{u} tracking, then you would know at least they
> used to have up to C in their repository to limit your check, but
> you cannot unconditionally say ref@{u}.. without making sure ref@{u}
> makes sense in the first place.
>
> An obvious alternative for the sample script would be to instead let
> the non-ff push pass the pre-push check (as you may have other
> arrangements to forbid non-ff pushes) without actually checking
> anything.  As this sample script is to serve as a sample, I think
> such an advanced consideration of loosening checks depending on the
> situation should be left to the end users.
>
Previous: Junio C Hamano
Message 5 of 5 in “Sample pre-push hook can crash”
  1. Stephen MortonMar 10, 2016
  2. Junio C HamanoMar 10, 2016
  3. Stephen MortonMar 11, 2016
  4. Junio C HamanoMar 11, 2016
  5. Stephen MortonMar 11, 2016

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.