threads / discuss / 26455

Advices to imlement update hook

Subject: Advices to imlement update hook

## tl;dr

6 messages between Feb 9, 2011 and Feb 10, 2011.

replies: 5people: 3as markdown or json

Francis Moreau· Feb 9, 2011, 16:27 UTC · lore
Hi !

I'd like to restrict access to one of my repos: the project tracked by it has several directories: a/ b/ c/ and I'd like to allow only modifications happen in b/ directory.

I'm planning to use git hooks, not sure which one I should use: if the check should happen at the commit or push time or both.

For now I'm going to use the update hook, so it will happen when pushing.
Now the question is: what is the best way to do this ?

I'm planning to use something equivalent to "git-diff-tree oldref newref | { grep -v b || exit 1; }" but doesn't look like the best git way.

BTW, from the git-diff-tree manpage:
	<path>...
	    If provided, the results are limited to a subset of
	    files matching one of these prefix strings. i.e., file
	    matches /^<pattern1>|<pattern2>|.../ Note that this
	    parameter does not provide any wildcard or regexp
	    features.

What does it mean exactly ? what does 'pattern' word mean if wildcard or regexp is not supported ? I also tried:

   git diff-tree <oldref> <newref> -- ^b || exit 1
but it doesn't work.
Could anybody give me some advices ?
Thanks
-- 
Francis
Johannes Sixt· Feb 9, 2011, 16:38 UTC · re: Francis Moreau · lore

Re: Advices to imlement update hook

Am 2/9/2011 17:27, schrieb Francis Moreau:
Show 33 quoted lines
> Hi !
> 
> I'd like to restrict access to one of my repos: the project tracked by
> it has several directories: a/ b/ c/ and I'd like to allow only
> modifications happen in b/ directory.
> 
> I'm planning to use git hooks, not sure which one I should use: if the
> check should happen at the commit or push time or both.
> 
> For now I'm going to use the update hook, so it will happen when pushing.
> 
> Now the question is: what is the best way to do this ?
> 
> I'm planning to use something equivalent to "git-diff-tree oldref
> newref | { grep -v b || exit 1; }" but doesn't look like the best git
> way.
> 
> BTW, from the git-diff-tree manpage:
> 
> 	<path>...
> 	    If provided, the results are limited to a subset of
> 	    files matching one of these prefix strings. i.e., file
> 	    matches /^<pattern1>|<pattern2>|.../ Note that this
> 	    parameter does not provide any wildcard or regexp
> 	    features.
> 
> What does it mean exactly ? what does 'pattern' word mean if wildcard
> or regexp is not supported ?
> I also tried:
> 
>    git diff-tree <oldref> <newref> -- ^b || exit 1
> 
> but it doesn't work.
  git diff-tree --quiet <oldref> <newref> -- b
Johannes Sixt· Feb 9, 2011, 16:42 UTC · re: Johannes Sixt · lore

Re: Advices to imlement update hook

[Sorry, sent too early - fat fingers :-(]
Am 2/9/2011 17:38, schrieb Johannes Sixt:
Show 9 quoted lines
> Am 2/9/2011 17:27, schrieb Francis Moreau:
>> Hi !
>>
>> I'd like to restrict access to one of my repos: the project tracked by
>> it has several directories: a/ b/ c/ and I'd like to allow only
>> modifications happen in b/ directory.
>>
>> I'm planning to use git hooks, not sure which one I should use: if the
>> check should happen at the commit or push time or both.
...
Show 7 quoted lines
>> I also tried:
>>
>>    git diff-tree <oldref> <newref> -- ^b || exit 1
>>
>> but it doesn't work.
> 
>   git diff-tree --quiet <oldref> <newref> -- b
should do it; it sets the exit code.

But don't you also want to inspect all commits between oldref and newref? Someone could have modified the directory, and then reverted the modification in a later commit. If these commits arrive in a single push, the above code wouldn't notice this.

-- Hannes
Francis Moreau· Feb 9, 2011, 16:51 UTC · re: Johannes Sixt · lore

Re: Advices to imlement update hook

On Wed, Feb 9, 2011 at 5:42 PM, Johannes Sixt <j.sixt@viscovery.net> wrote:
Show 22 quoted lines
> [Sorry, sent too early - fat fingers :-(]
>
> Am 2/9/2011 17:38, schrieb Johannes Sixt:
>> Am 2/9/2011 17:27, schrieb Francis Moreau:
>>> Hi !
>>>
>>> I'd like to restrict access to one of my repos: the project tracked by
>>> it has several directories: a/ b/ c/ and I'd like to allow only
>>> modifications happen in b/ directory.
>>>
>>> I'm planning to use git hooks, not sure which one I should use: if the
>>> check should happen at the commit or push time or both.
> ...
>>> I also tried:
>>>
>>>    git diff-tree <oldref> <newref> -- ^b || exit 1
>>>
>>> but it doesn't work.
>>
>>   git diff-tree --quiet <oldref> <newref> -- b
>
> should do it; it sets the exit code.
but does that work if a commit modify b/ and another directory ?
> But don't you also want to inspect all commits between oldref and newref?
Yes I want to inspect all commits in the range.
> Someone could have modified the directory, and then reverted the
> modification in a later commit. If these commits arrive in a single push,
> the above code wouldn't notice this.

I agree but I thought that git diff-tree would list all changes made between the 2 refs.

Thanks
-- 
Francis
Jeff King· Feb 9, 2011, 17:05 UTC · re: Francis Moreau · lore

Re: Advices to imlement update hook

On Wed, Feb 09, 2011 at 05:51:24PM +0100, Francis Moreau wrote:
Show 9 quoted lines
> >>>    git diff-tree <oldref> <newref> -- ^b || exit 1
> >>>
> >>> but it doesn't work.
> >>
> >>   git diff-tree --quiet <oldref> <newref> -- b
> >
> > should do it; it sets the exit code.
> 
> but does that work if a commit modify b/ and another directory ?

No, it just looks for commits that modified b. There is currently no way to specify a path to say "commit that did not modify b". You need to check the output of:

  git rev-list | git diff-tree --stdin -m --name-only

which should list all paths modified by all commits. And then you can either blacklist or whitelist as appropriate (note that the names can be quoted; you might want to look at the "-z" option and do your list-checking in perl).

> > But don't you also want to inspect all commits between oldref and newref?
> 
> Yes I want to inspect all commits in the range.
see above.
Show 6 quoted lines
> > Someone could have modified the directory, and then reverted the
> > modification in a later commit. If these commits arrive in a single push,
> > the above code wouldn't notice this.
> 
> I agree but I thought that git diff-tree would list all changes made
> between the 2 refs.

Between the two endpoints. It won't even look at the commits in the middle, so as long as a later middle commit reverts the change of an earlier middle commit, the endpoints won't be affected.

-Peff
Francis Moreau· Feb 10, 2011, 13:24 UTC · re: Jeff King · lore

Re: Advices to imlement update hook

Hello,
On Wed, Feb 9, 2011 at 6:05 PM, Jeff King <peff@peff.net> wrote:
Show 39 quoted lines
> On Wed, Feb 09, 2011 at 05:51:24PM +0100, Francis Moreau wrote:
>
>> >>>    git diff-tree <oldref> <newref> -- ^b || exit 1
>> >>>
>> >>> but it doesn't work.
>> >>
>> >>   git diff-tree --quiet <oldref> <newref> -- b
>> >
>> > should do it; it sets the exit code.
>>
>> but does that work if a commit modify b/ and another directory ?
>
> No, it just looks for commits that modified b. There is currently no way
> to specify a path to say "commit that did not modify b". You need to
> check the output of:
>
>  git rev-list | git diff-tree --stdin -m --name-only
>
> which should list all paths modified by all commits. And then you can
> either blacklist or whitelist as appropriate (note that the names can be
> quoted; you might want to look at the "-z" option and do your
> list-checking in perl).
>
>> > But don't you also want to inspect all commits between oldref and newref?
>>
>> Yes I want to inspect all commits in the range.
>
> see above.
>
>> > Someone could have modified the directory, and then reverted the
>> > modification in a later commit. If these commits arrive in a single push,
>> > the above code wouldn't notice this.
>>
>> I agree but I thought that git diff-tree would list all changes made
>> between the 2 refs.
>
> Between the two endpoints. It won't even look at the commits in the
> middle, so as long as a later middle commit reverts the change of an
> earlier middle commit, the endpoints won't be affected.
Oh, I see. I undestand why the git-rev-list is needed now.
Thanks for your help !
-- 
Francis

← back to recent threads