update hook: squelch message for branch deletion
Ilari pointed out that in case of branch deletion the *new* SHA could be 0, which causes an ugly fatal: Not a valid commit name 0000000000000000000000000000000000000000 Since we consider deletion an extreme form of rewind, the end result does not change ($merge_base will be unequal to $oldsha anyway), but we do need to squelch the ugly message.
This commit is contained in:
parent
0f726bea9a
commit
92cf77d9c2
|
@ -55,17 +55,21 @@ my $ref = shift;
|
||||||
my $oldsha = shift;
|
my $oldsha = shift;
|
||||||
my $newsha = shift;
|
my $newsha = shift;
|
||||||
my $merge_base = '0' x 40;
|
my $merge_base = '0' x 40;
|
||||||
|
# compute a merge-base if both SHAs are non-0, else leave it as '0'x40
|
||||||
|
# (i.e., for branch create or delete, merge_base == '0'x40)
|
||||||
chomp($merge_base = `git merge-base $oldsha $newsha`)
|
chomp($merge_base = `git merge-base $oldsha $newsha`)
|
||||||
unless $oldsha eq '0' x 40;
|
unless $oldsha eq '0' x 40
|
||||||
|
or $newsha eq '0' x 40;
|
||||||
|
|
||||||
# some of this is from an example hook in Documentation/howto of git.git, with
|
# some of this is from an example hook in Documentation/howto of git.git, with
|
||||||
# some variations
|
# some variations
|
||||||
|
|
||||||
# what are you trying to do? (is it 'W' or '+'?)
|
# what are you trying to do? (is it 'W' or '+'?)
|
||||||
my $perm = 'W';
|
my $perm = 'W';
|
||||||
# rewriting a tag
|
# rewriting a tag is considered a rewind, in terms of permissions
|
||||||
$perm = '+' if $ref =~ m(refs/tags/) and $oldsha ne ('0' x 40);
|
$perm = '+' if $ref =~ m(refs/tags/) and $oldsha ne ('0' x 40);
|
||||||
# non-ff push to branch
|
# non-ff push to branch. Notice that branch delete looks like a rewind, as it
|
||||||
|
# should
|
||||||
$perm = '+' if $ref =~ m(refs/heads/) and $oldsha ne $merge_base;
|
$perm = '+' if $ref =~ m(refs/heads/) and $oldsha ne $merge_base;
|
||||||
|
|
||||||
my $allowed_refs = $repos{$ENV{GL_REPO}}{$perm}{$ENV{GL_USER}};
|
my $allowed_refs = $repos{$ENV{GL_REPO}}{$perm}{$ENV{GL_USER}};
|
||||||
|
|
Loading…
Reference in a new issue