git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* git rebase backend change: post-checkout hook is not ran by 'merge' backend
@ 2020-04-02 15:57 Philippe Blain
  2020-04-02 16:00 ` Philippe Blain
  2020-04-02 16:58 ` Elijah Newren
  0 siblings, 2 replies; 4+ messages in thread
From: Philippe Blain @ 2020-04-02 15:57 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: git rebase backend change: post-checkout hook is not ran by 'merge' backend
  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
  1 sibling, 0 replies; 4+ messages in thread
From: Philippe Blain @ 2020-04-02 16:00 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren

Sorry, the last rebase command is missing:

   $ 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>
   $ git rebase upstream/master --merge
   Successfully rebased and updated refs/heads/<branch2>

> Le 2 avr. 2020 à 11:57, Philippe Blain <levraiphilippeblain@gmail.com> a écrit :
> 
>    $ 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>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: git rebase backend change: post-checkout hook is not ran by 'merge' backend
  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
  2020-04-03  9:08   ` Phillip Wood
  1 sibling, 1 reply; 4+ messages in thread
From: Elijah Newren @ 2020-04-02 16:58 UTC (permalink / raw)
  To: Philippe Blain; +Cc: git, Jonathan Nieder, Emily Shaffer

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/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: git rebase backend change: post-checkout hook is not ran by 'merge' backend
  2020-04-02 16:58 ` Elijah Newren
@ 2020-04-03  9:08   ` Phillip Wood
  0 siblings, 0 replies; 4+ messages in thread
From: Phillip Wood @ 2020-04-03  9:08 UTC (permalink / raw)
  To: Elijah Newren, Philippe Blain; +Cc: git, Jonathan Nieder, Emily Shaffer

Hi

On 02/04/2020 17:58, Elijah Newren wrote:
> 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>

The merge backend runs `git checkout` to do the checkout and so does 
actually run the post-checkout hook. However the invocation is wrapped 
in run_command_silent_on_success() which means if the checkout is 
successful you don't see the output from the hook (and if the checkout 
fails you don't see the output from the hook because it is not run). You 
can verify this by changing the first line of your example to

$ echo "echo \"Running post-checkout hook\" >>/tmp/post-checkout" > 
.git/hooks/post-checkout

and examining /tmp/post-checkout

>> 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?

cherry-pick/revert don't check anything out

>  What about reset or merge?

again they are not checking out an existing commit.

However the 'reset' command for rebase -r is checking out an existing 
commit so if we decide to keep running the hook for the initial checkout 
then I think we should do it after those commands as well as there's 
nothing special about the initial checkout.

As for whether we should be running the hook I think it depends on what 
people are using it for. If they have a pair of pre-commit and 
post-checkout hooks to handle file metadata such as permissions and acls 
they might want to run the post-checkout hook so the file metadata gets 
updated but then there is no support for this when picking the rebased 
commits so it's arguably pointless to do it on the initial checkout.

If they are using it to be notified of branch switches then maybe we 
don't need to run it when checking out the onto commit (unless they want 
to know that we've switched to a detached HEAD). Though we would still 
want to do it for the branch switch in 'git rebase <upstream> <branch>'

As you can see I'm waffling and have no idea what's the right thing to do!

Best Wishes

Phillip


> 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/
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-04-03  9:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2020-04-03  9:08   ` Phillip Wood

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).