git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Elijah Newren <newren@gmail.com>
To: Philippe Blain <levraiphilippeblain@gmail.com>
Cc: git <git@vger.kernel.org>, Jonathan Nieder <jrnieder@gmail.com>,
	Emily Shaffer <emilyshaffer@google.com>
Subject: Re: git rebase backend change: post-checkout hook is not ran by 'merge' backend
Date: Thu, 2 Apr 2020 09:58:14 -0700	[thread overview]
Message-ID: <CABPp-BG0bFKUage5cN_2yr2DkmS04W2Z9Pg5WcROqHznV3XBdw@mail.gmail.com> (raw)
In-Reply-To: <9945492E-1D97-4741-B999-F30CA561D4DE@gmail.com>

Hi,

On Thu, Apr 2, 2020 at 8:57 AM Philippe Blain
<levraiphilippeblain@gmail.com> 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@google.com/
[2] https://lore.kernel.org/git/20200115215922.GI181522@google.com/

  parent reply	other threads:[~2020-04-02 16:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-02 15:57 git rebase backend change: post-checkout hook is not ran by 'merge' backend Philippe Blain
2020-04-02 16:00 ` Philippe Blain
2020-04-02 16:58 ` Elijah Newren [this message]
2020-04-03  9:08   ` Phillip Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CABPp-BG0bFKUage5cN_2yr2DkmS04W2Z9Pg5WcROqHznV3XBdw@mail.gmail.com \
    --to=newren@gmail.com \
    --cc=emilyshaffer@google.com \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    --cc=levraiphilippeblain@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).