Sorry, replied rather than replied to all with this - Alan please see below
 



________________________________
 From: phil rosenberg <philip_rosenb...@yahoo.com>
To: Hazen Babcock <hbabc...@mac.com> 
Sent: Sunday, 17 August 2014, 13:44
Subject: Re: [Plplot-devel] Trying to understand how git workflow for CMake is 
enforced
  


Hi Alan
I'm not great with shell scripts - I use them so infrequently I never remember 
the syntax. However I have quickly tried to modify the hook 
fromhttps://gist.github.com/caniszczyk/1327469. Basically you are trying to do 
something like:

git rev-list --first-parent newrev | grep `git rev-list --first-parent 
--max-count=1 oldrev`

where newrev is the revision being pushed and oldrev is the revision being 
updated.

If this gives an empty string then then newrev is not a direct descendant of 
oldrev. This could be because the merge was done the wrong way round (which is 
the check described on the CMAKE page) or because someone has modified oldrev 
on the server before the push occurred.

The command works because git rev-list --first-parent commit lists the sha 
values for each parent of the commit choosing only the first parent, rather 
than the merged in parent in the case of a merge. Therefore if you have merged 
the wrong way the new commit will not inherit from the parent of the old 
commit. Note that the one exception is a fast forward commit, however in this 
case the result is identical no matter which way the merge was performed so it 
makes no difference.

If you intend to have a "next" branch then you could also ensure that the topic 
branch being merged in inherits from master (instead of next or bugfixes or 
whatever), by branching next, making a change to master. Finding the sha for 
this first commit which is not on next and grepping for it in the same way as 
above.

Attached is my quick hack of that script which just replaces the requirement 
for fast forward merges only, with the requirement above - I haven't tested it 
or tried to run it and it will have windows line endings but I haven't got time 
right now. The syntax might be wrong, but I'm sure you can see the intent. I'm 
sure you can have a look at it and have a play with the git rev-list command to 
see what is happening and add stuff if you like.

All the best

Phil
 
 From: Hazen Babcock <hbabc...@mac.com>
To: Alan W. Irwin <ir...@beluga.phys.uvic.ca>; Hezekiah M. Carty 
<hezekiahca...@users.sourceforge.net> 
Cc: PLplot development list <Plplot-devel@lists.sourceforge.net> 
Sent: Sunday, 17 August 2014, 3:55
Subject: Re: [Plplot-devel] Trying to understand how git workflow for CMake is 
enforced
  

On 8/16/2014 1:50 PM, Alan W. Irwin wrote:
> On 2014-08-16 06:50-0400 Hezekiah M. Carty wrote:
>
>> I agree with Hazen here - adding hooks on day one seems overkill for
>> the
 project.  [...]
>> Given that the project and developers are overall new to git I think
>> it would be premature to start stacking automated restrictions on top
>> of our use of the tool.
>
> That said, I appreciate you and Hazen are anxious to get started with
> git for PLplot after such a long wait, and I also feel similarly even
> though I am pretty much still a git newbie.  So I suggest we should
> jointly review my decision (to not allow push to the official repo
> until we get the required modification of the update hook figured out)
> sometime late next week (say roughly in 6 days from now).  That gives
> enough time to find out if Brad King is willing to share his
> implementation, and also to
 pursue a lot further the backup plan of
> modifying .git/hooks/update(.sample) appropriately ourselves.

Unfortunately all I can report so far is that I have not had much luck 
with the obvious google searches such as "git hook enforce merge only". 
So while presumably this enforcement is possible, it also seems to be rare.

As an aside, an interesting
 client-side hook to develop would be one 
that automatically runs uncrustify. I know that I'm not very good about 
doing this manually.


-Hazen


------------------------------------------------------------------------------
_______________________________________________
Plplot-devel mailing list
Plplot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plplot-devel
#!/bin/sh

#
# For each ref, validate the commit.
#
# - It disallows deleting branches without a /.
# - It disallows non fast-forward on branches without a /.
# - It disallows deleting tags without a /.
# - It disallows unannotated tags to be pushed.

validate_ref()
{
        # --- Arguments
        oldrev=$(git rev-parse $1)
        newrev=$(git rev-parse $2)
        refname="$3"

        allownonffpush=$( git config --bool hooks.allownonffpush )
        allowdeletebranch=$( git config --bool hooks.allowdeletebranch )
        allowdeletetag=$( git config --bool hooks.allowdeletetag )
        allowcreatenottopicbranch=$( git config --bool 
hooks.allowcreatenottopicbranch )
        # oldrev could be 0s which means creating refname
        # newrev could be 0s which means deleting refname

        case "$refname" in
                refs/heads/*)
                        branch=$(expr "$refname" : "refs/heads/\(.*\)")
                        topicbranch=$(expr "$branch" : "\(.*/.*\)")
                        topicuser=$(expr "$branch" : "\(.*\)/.*")
                        if [ 0 -ne $(expr "$newrev" : "0*$") ]; then # deleting
                                # only topic branches can be deleted
                                if [ "$allowdeletebranch" != "true" -a -z 
"$topicbranch" ]; then
                                        fail=1
                                        echo >&2 "*** Deleting the branch 
$branch is not permitted. ***"
                                        return
                                fi
                                if [  "$allowdeletebranch" != "true" -a "$USER" 
!= "$topicuser" ]; then
                                        fail=1
                                        echo >&2 "*** Deleting the branch 
$branch is not permitted by $USER. ***"
                                        return
                                fi
                                return # Don't need to validate old revision
                        else #updating
                                if [ 0 -ne $(expr "$oldrev" : "0*$") ]; then # 
pushing a new branch
                                        if [ "$allowcreatenottopicbranch" != 
"true" -a -z "$topicbranch" ]; then
                                                fail=1
                                                echo >&2 "*** creation of 
branch $branch is not permitted. ***"
                                        fi
                                        return # it's not a FF merge
                                fi
                                oldrevparent=`git rev-list --first-parent 
--max-count=1 oldrev`
                                if [ "" -eq `git rev-list --first-parent newrev 
| grep oldrevparent` ]; then # non fast-forward
                                        fail=1
                                        echo >&2 "*** Branch merge has been 
performed the wrong way round or the branch has been modified since the merge. 
***"
                                fi
                        fi
                        ;;
                refs/tags/*)
                    tag=$(expr "$refname" : "refs/tags/\(.*\)")
                        topictag=$(expr "$tag" : "\(.*/.*\)")
                        topicuser=$(expr "$tag" : "\(.*\)/.*")
                        if [ 0 -ne $(expr "$newrev" : "0*$") ]; then # deleting
                                # only topic tags can be deleted
                                if [ "$allowdeletetag" != "true" -a -z 
"$topictag" ]; then
                                        fail=1
                                        echo >&2 "*** Deleting the tag $tag is 
not permitted. ***"
                                        return
                                fi
                                if [  "$allowdeletetag" != "true" -a "$USER" != 
"$topicuser" ]; then
                                        fail=1
                                        echo >&2 "*** Deleting the tag $tag is 
not permitted by $USER. ***"
                                        return
                                fi
                                return
                        fi
                        ;;
                *)
                        fail=1
                        echo >&2 "*** pre-receive hook does not understand ref 
$refname in this repository. ***"
                        echo >&2 "*** Contact the repository administrator. ***"
                        ;;
        esac
}

fail=""

# Allow dual mode: run from the command line just like the update hook, or
# if no arguments are given then run as a hook script
if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
        # Output to the terminal in command line mode - if someone wanted to
        # resend an email; they could redirect the output to sendmail
        # themselves
        PAGER= validate_ref $2 $3 $1
else
        while read oldrev newrev refname
        do
                validate_ref $oldrev $newrev $refname
        done
fi

if [ -n "$fail" ]; then
        exit $fail
fi
------------------------------------------------------------------------------
_______________________________________________
Plplot-devel mailing list
Plplot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plplot-devel

Reply via email to