From: Junio C Hamano <hidden> Date: 2018-02-10 01:08:33
Leo Gaspard [off-list ref] writes:
On 02/10/2018 01:13 AM, Jeff King wrote:
quoted
On Sat, Feb 10, 2018 at 12:49:31AM +0100, Leo Gaspard wrote:
quoted
So the changes that are required are:
* Adding a notification-only post-fetch hook
Maybe I missed a very early part of the discussion, but why does
this even need a hook? There are some numbers [*1*] of classes of
valid reasons we may want to have hooks triggered by operations, but
"always do something locally after doing something else locally,
regardless of the outcome of that something else" feels like the
most typical anti-pattern that we do not want a hook for. If you
are doing "git fetch" (or "git pull"), you already know you are
doing that and you donot need a notification. You just create a
workflow specific script that calls fetch or pull, followed by
whatever you want to do and use that, instead of doing "git pull",
and that is not any extra work than writing a hook and installing
it.
Unlike something like post-receive, which happens on the remote side
where you may not even have an interactive access to, in response to
the operation you locally do (i.e. "git push"), fetching and then
doing something else in a repository you fetch into has no reason to
be done as a hook.
[Footnote]
*1* I think the number was 5 when I last counted/enumerated, but
don't quote me on that ;-)
From: Leo Gaspard <hidden> Date: 2018-02-10 01:33:26
On 02/10/2018 02:08 AM, Junio C Hamano wrote:
Leo Gaspard [off-list ref] writes:
quoted
On 02/10/2018 01:13 AM, Jeff King wrote:
quoted
On Sat, Feb 10, 2018 at 12:49:31AM +0100, Leo Gaspard wrote:
quoted
So the changes that are required are:
* Adding a notification-only post-fetch hook
Maybe I missed a very early part of the discussion, but why does
this even need a hook? There are some numbers [*1*] of classes of
valid reasons we may want to have hooks triggered by operations, but
"always do something locally after doing something else locally,
regardless of the outcome of that something else" feels like the
most typical anti-pattern that we do not want a hook for. If you
are doing "git fetch" (or "git pull"), you already know you are
doing that and you donot need a notification. You just create a
workflow specific script that calls fetch or pull, followed by
whatever you want to do and use that, instead of doing "git pull",
and that is not any extra work than writing a hook and installing
it.
Unlike something like post-receive, which happens on the remote side
where you may not even have an interactive access to, in response to
the operation you locally do (i.e. "git push"), fetching and then
doing something else in a repository you fetch into has no reason to
be done as a hook.
I guess the very early part of the discussion you're speaking of is what
I was assuming after reading
https://marc.info/?l=git&m=132478296309094&w=2
Then, it's always possible to just write workflow-specific scripts that
manually run git fetch then copy the refs (resp. run git fetch then copy
the refs then run git merge) to get git myfetch (resp. git mypull) [1].
But then, the question is, why is there a pre-push hook? it's already
possible to have a custom script that first runs the hook then runs git
push, for most if not all of the use cases of the pre-push hook. Yet the
possibility to not change the end-user's workflow is what makes pre-push
(or pre-commit, with which the similarity is perhaps even more obvious)
so useful.
So the reason for a post-fetch in my opinion is the same as for a
pre-push / pre-commit: not changing the user's workflow, while providing
additional features.
[1]
Which makes me notice that actually the post-fetch hook technique we
were discussing with Peff suffers the same not-updating-FETCH_HEAD issue
that was discussed in this early thread: a `git pull` would try to merge
from refs/quarantine, I guess. So things are a bit harder than we thought.
I guess the tweak-fetch hook could be left “as-is”, but with git
automatically doing the “quarantine-ing” thing transparently so that the
references that the end-user (or the hook for that matter) see are the
“curated” ones? Then it's too late for me to think efficiently right
now, so that idea may be stupid or over-complex.
From: Leo Gaspard <hidden> Date: 2018-02-10 18:03:41
On 02/10/2018 02:33 AM, Leo Gaspard wrote:> I guess the very early part
of the discussion you're speaking of is what
I was assuming after reading
https://marc.info/?l=git&m=132478296309094&w=2
[...]
So the reason for a post-fetch in my opinion is the same as for a
pre-push / pre-commit: not changing the user's workflow, while providing
additional features.
Well, re-reading my email, it looks aggressive to me now... sorry about
that!
What I meant was basically, that in my mind pre-push or pre-commit are
also local-only things, and they are really useful in that they allow to
block the push or the commit if some conditions are not met (eg. block
commit with trailing whitespace, or block push of unsigned commits).
In pretty much the same way, what I'm really looking for is a way to
“block the fetch” (from a user-visible standpoint) -- like pre-push but
in the opposite direction. I hope such a goal is not an anti-pattern for
hook design?
In order to do this, I first tried updating this tweak-fetch hook patch
from late 2011, and then learned that it would cause too high a load on
servers. Then, while brainstorming another solution, this idea of a
notification-only post-fetch hook arose. But, as I noticed while writing
my previous answer, this suffers the same
the-hook-writer-must-correctly-update-FETCH_HEAD-concurrently-with-remote-branch
issue that you pointed out just after the “*HOWEVER*” in [1]. So that
solution is likely a bad solution too. I guess we'll continue the search
for a good solution in the side-thread with Peff, hoping to figure one out.
That being said about what I meant in my last email, obviously you're
the one who has the say on what goes in or not! And if it's an
anti-feature I'd much rather know it now than after spending a few
nights coding :)
So, what do you think about this use case I'm thinking of? (ie.
“blocking the fetch” like pre-push “blocks the push” and pre-commit
“blocks the commit”?)
[1] https://marc.info/?l=git&m=132478296309094&w=2