# Re: [PATCH] [RFC] Make git-update-ref invoke the update and post-update hooks

5 messages from 2015-06-15 to 2015-06-16. Participants: Brian Vandenberg, Junio C Hamano.
Thread: https://gitlist.dev/t/39637

## Brian Vandenberg, 2015-06-15 19:49

Subject: Re: [PATCH] [RFC] Make git-update-ref invoke the update and post-update hooks
Message-ID: <CAEJ-0i-BB=5W-Ah3nkeLFCe5-4XW4CvYaDgdqv1mMp4UGF81qw@mail.gmail.com>
URL: https://gitlist.dev/e/CAEJ-0i-BB%3D5W-Ah3nkeLFCe5-4XW4CvYaDgdqv1mMp4UGF81qw%40mail.gmail.com

```
From: Junio C Hamano <junkio@cox.net>
Date: 2006-10-08 15:00:32
Petr Baudis <pasky@suse.cz> writes:

>> Someone raised a concern that the update and post-update hooks are not
>> invoked at fetch time in the similar way as they are invoked at push
>> time, and the idea sort of makes sense. But this patch goes further - it
>> makes Git invoke those hooks each time a ref is updated in a repository
>> using the git-update-ref command, which I believe makes a lot of sense as
>> well - the behaviour is consistent with the current pushing behaviour
>> and you suddenly finally get a hook where you can properly notify even
>> about fast-forwards etc.

>In principle I do not have problem with this approach per-se,
>but I wonder if we were to do this we might want to make
>receive-pack.c::update() and cmd_update_ref() call the same
>underlying function, and make that underlying function implement
>this "ask the hook if updating is ok" dance.  It might even make
>sense to have update-ref honor deny_non_fast_forwards for that
>matter (I am mildly doubtful of this last point, though).

Was this rejected?

I'm tweaking the configuration on our master repo; among other things:
I've enabled reflog and disabled altering history or deleting branches
through receive-pack, instead requiring that someone make history
alterations directly (using update-ref).

update-ref can optionally accept a comment explaining why the history
needed to be altered, but we would prefer to make it mandatory.  Hooks
seem like a natural place to do that, but after running update-ref
under strace/truss & looking through builtin/update-ref.c, it looks as
though it doesn't make use of hooks.

-Brian

```

## Junio C Hamano, 2015-06-15 20:22

Subject: Re: [PATCH] [RFC] Make git-update-ref invoke the update and post-update hooks
Message-ID: <xmqqpp4w7mco.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqqpp4w7mco.fsf%40gitster.dls.corp.google.com
In-Reply-To: <CAEJ-0i-BB=5W-Ah3nkeLFCe5-4XW4CvYaDgdqv1mMp4UGF81qw@mail.gmail.com>

```
Brian Vandenberg <phantall@gmail.com> writes:

> From: Junio C Hamano <junkio@cox.net>
> Date: 2006-10-08 15:00:32
> Petr Baudis <pasky@suse.cz> writes:
>
>>> Someone raised a concern that the update and post-update hooks are not
>>> invoked at fetch time in the similar way as they are invoked at push
>>> time, and the idea sort of makes sense. But this patch goes further - it
>>> makes Git invoke those hooks each time a ref is updated in a repository
>>> using the git-update-ref command, which I believe makes a lot of sense as
>>> well - the behaviour is consistent with the current pushing behaviour
>>> and you suddenly finally get a hook where you can properly notify even
>>> about fast-forwards etc.
>
>>In principle I do not have problem with this approach per-se,
>>but I wonder if we were to do this we might want to make
>>receive-pack.c::update() and cmd_update_ref() call the same
>>underlying function, and make that underlying function implement
>>this "ask the hook if updating is ok" dance.  It might even make
>>sense to have update-ref honor deny_non_fast_forwards for that
>>matter (I am mildly doubtful of this last point, though).

I am ultra-doubtful at this point ;-)

For one thing, update-ref is not a tool that is exclusive to
receiving object transfer aka receive-pack, so it makes no sense for
it to pay attention to post-update.

Also it is a low-level plumbing; the policy issues should come at a
level higher than that.  I.e. Porcelain scripts implemented using
them as building blocks should be the ones that you do your policy,
e.g.

	if whatever logic you want to use in your policy says OK
        then
		git update-ref ...args...
	else
        	echo >&2 "My policy does not like your arguments"
                exit 1
	fi

```

## Brian Vandenberg, 2015-06-15 20:58

Subject: Re: [PATCH] [RFC] Make git-update-ref invoke the update and post-update hooks
Message-ID: <CAEJ-0i8mfabWoLivX_ZJHRJBYFftoENWmHw5__CGphK54oOpug@mail.gmail.com>
URL: https://gitlist.dev/e/CAEJ-0i8mfabWoLivX_ZJHRJBYFftoENWmHw5__CGphK54oOpug%40mail.gmail.com
In-Reply-To: <xmqqpp4w7mco.fsf@gitster.dls.corp.google.com>

```
On Mon, Jun 15, 2015 at 2:22 PM, Junio C Hamano <gitster@pobox.com> wrote:
> I am ultra-doubtful at this point ;-)
>
> For one thing, update-ref is not a tool that is exclusive to
> receiving object transfer aka receive-pack, so it makes no sense for
> it to pay attention to post-update.

I was a little dubious about that as well, though I like the idea of
update-ref having a hook.

> Also it is a low-level plumbing; the policy issues should come at a
> level higher than that.  I.e. Porcelain scripts implemented using
> them as building blocks should be the ones that you do your policy,
> e.g.
>
>         if whatever logic you want to use in your policy says OK
>         then
>                 git update-ref ...args...
>         else
>                 echo >&2 "My policy does not like your arguments"
>                 exit 1
>         fi
>

In principle I agree, though telling people "you should use xyz
script" is one thing; in practice they're more likely to google "git
alter history" and eventually find an explanation for using
update-ref, completely bypassing any policy/protocol we put in place
for altering history on the master repo.

Would you be less doubtful about adding a lower-level hook for
update-ref?  Or in lieu of that, a config option that can affect the
behavior of its "-m" and "-d" options?

-Brian

```

## Junio C Hamano, 2015-06-15 21:45

Subject: Re: [PATCH] [RFC] Make git-update-ref invoke the update and post-update hooks
Message-ID: <xmqqd20w7ii4.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqqd20w7ii4.fsf%40gitster.dls.corp.google.com
In-Reply-To: <CAEJ-0i8mfabWoLivX_ZJHRJBYFftoENWmHw5__CGphK54oOpug@mail.gmail.com>

```
Brian Vandenberg <phantall@gmail.com> writes:

> Would you be less doubtful about adding a lower-level hook for
> update-ref?  Or in lieu of that, a config option that can affect the
> behavior of its "-m" and "-d" options?

Not really.

Those who want to bypass your policy can use "vi .git/packed-refs"
and/or "rm .git/refs/heads/foo"; you would not propose to patch "rm"
and "vi" to pay attention to git configuration, because they are not
about "git" at all, and there are cases where these bare-metal level
editing of repositories is necessary.  You would instead tell them
"don't do that".

When I say "update-ref is a low-level plumbing command that should
not enforce policy", I am suggesting you to treat the command just
like you would treat "rm" and "vi".

```

## Brian Vandenberg, 2015-06-16 14:31

Subject: Re: [PATCH] [RFC] Make git-update-ref invoke the update and post-update hooks
Message-ID: <CAEJ-0i-QptjYLtr0CnYOgt4X+2R5tQGZqRhicFdxAPBxNA8J7Q@mail.gmail.com>
URL: https://gitlist.dev/e/CAEJ-0i-QptjYLtr0CnYOgt4X%2B2R5tQGZqRhicFdxAPBxNA8J7Q%40mail.gmail.com
In-Reply-To: <xmqqd20w7ii4.fsf@gitster.dls.corp.google.com>

```
On Mon, Jun 15, 2015 at 3:45 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Those who want to bypass your policy can use "vi .git/packed-refs"
> and/or "rm .git/refs/heads/foo"; you would not propose to patch "rm"
> and "vi" to pay attention to git configuration, because they are not
> about "git" at all, and there are cases where these bare-metal level
> editing of repositories is necessary.  You would instead tell them
> "don't do that".
>
> When I say "update-ref is a low-level plumbing command that should
> not enforce policy", I am suggesting you to treat the command just
> like you would treat "rm" and "vi".

I suppose I see your point, though the line they've crossed at that
point is from benign to malicious.

When you assume they've crossed that line, hooks and configuration
parameters are mostly useless in other git commands as well.  My
assumption here is they want to do something productive and aren't
intentionally seeking to subvert policies, but rather aren't aware of
the policies and/or correct procedure.

Thanks for your responses, I appreciate your time.

-Brian

```
