Re: git rebase backend change: post-checkout hook is not ran by 'merge' backend

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Thu, Apr 2, 2020 at 8:57 AM Philippe Blain
<levraiphilippeblain@xxxxxxxxx> wrote:
>
> Hello,
>
> I'm not sure if this has been reported yet (couldn't find it),
> but I noticed a behavioral difference between the merge
> and apply backends that is not mentioned in the documentation:
> The 'apply' backend will run the post-checkout hook just after
> moving HEAD to the commit we are rebasing onto;
> this does not happen with the merge backend:
>
>     $ echo "echo \"Running post-checkout hook\"" > .git/hooks/post-checkout
>     $ git checkout -b <branch1> <commit2>
>     $ git rebase upstream/master --apply
>     First, rewinding head to replay your work on top of it...
>     Running post-checkout hook
>     Applying: <commit1>
>     Applying: <commit2>
>     $ git checkout -b <branch2> <commit2>
>     Successfully rebased and updated refs/heads/<branch2>
>
> Cheers,
> Philippe.

Interesting.  We had a report about the post-commit hook, but not
about post-checkout.  From the description in the githooks manpage
it's not clear to me that either rebase backend is correct or
incorrect here, but they should at least be consistent.  Also, if
rebase should call post-checkout, should cherry-pick?  If cherry-pick
should, should commit or revert call it?  What about reset or merge?
This hook to me seems to be rather badly defined because If any
operations other than checkout/switch should call it, then you've got
various angles of weirdness if you don't include all the others too.
(Also, digging through the history, the only reason that the apply
backend called the post-checkout hook was because it was written as a
script and invoked 'git checkout'.  But then someone noticed that the
scripted version called the hook and thus ported it to the builtin.)
>From another angle, maybe you could make the cutoff be only when HEAD
changes which symref it points to (meaning rebase would only call it
if you asked it to rebase a different branch than you were on), but
that has its own weirdness too.  I think this hook is really weird,
unless we restrict it to only the things already explicitly mentioned
in the githooks manpage.

In any event, I guess that means we need to update this section of the
rebase manpage:

"""
Hooks
~~~~~

The apply backend has not traditionally called the post-commit hook,
while the merge backend has.  However, this was by accident of
implementation rather than by design.  Both backends should have the
same behavior, though it is not clear which one is correct.
"""

to also mention post-checkout, note that the situation about which
backend calls this hook is reversed relative to post-commit, and again
mention it's not clear which backend is correct.

My very rough opinion of the moment is:
  * post-checkout should probably do as the manpage says, and only run
for checkout/switch plus new worktree situations (worktree add/clone).
rebase --apply should stop calling it.
  * post-commit is horribly broken; it hardcodes an assumption of
exactly one commit.  Also, it's a huge performance problem when things
want to create multiple commits.  So, let's do as the githooks manpage
suggest and call this hook from a direct "git commit" -- and _only_
from there.  Remove it from rebase, cherry-pick, revert, etc.
Normally, for consistency, I would say that merge should start calling
that hook (it only creates one commit, and "git commit" is used to
complete an interrupted merge anyway so why not uninterrupted ones),
but merge can be called by rebase --rebase-merges right now so that
pushes us back to the get it out of rebase side.  The hook is kinda
broken anyway, so maybe limit exposure?
  * Make a new post-batch-commit hook called by things that create new
commits, but only call it once per operation (e.g. rebase and
cherry-pick call it once rather than once per commit).  Have commit,
merge, and revert all call this too.  Not sure what to do about things
that change multiple refs simultaneously, e.g. fast-import (or things
like it, e.g. filter-branch).

CC'ing Jonathan and Emily since they've thought a lot about hooks, and
whom I thought might be making changes in this area[1][2].


Elijah

[1] https://lore.kernel.org/git/20200116203521.GA71299@xxxxxxxxxx/
[2] https://lore.kernel.org/git/20200115215922.GI181522@xxxxxxxxxx/



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux