Skip to content

Commit

Permalink
gerrit/hooks: Fix all the things
Browse files Browse the repository at this point in the history
* Gerrit runs these hooks multiple times on a single commit
  • Loading branch information
kallisti5 committed Aug 6, 2019
1 parent bdc623b commit 4ba8714
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
25 changes: 1 addition & 24 deletions data/gerrit/hooks/receive-notify.pl
Expand Up @@ -668,30 +668,7 @@ ($)
my ($ref) = @_;
my $branch = "";

if ($ref =~ m/refs\/changes\//) {
print "Detected accepted Gerrit Changeset. Parsing for accepted patches...\n";
$ref =~ s/\/meta$//;
# This is kind of shite. Gerrit gives us "refs/changes/79/1679/meta" while
# merging the "patchset id" into master. (refs/changes/79/1679/3 for example)
# We run git branch --contains refs/changes/79/1679/1..50 searching for the
# accepted patchset. Please improve if you can.
foreach my $patchset (0..50) {
if ($branch ne "") {
next;
}
open BRANCHES, "-|" or exec "git", "branch", "--contains", "$ref/$patchset" or die "cannot exec git-branch";
map
{
chomp;
die "invalid branch $_" unless /^.*[0-9a-f]*$/;
$branch = $_;
$branch =~ s/^\s*\**\s*//;
print $branch;
$branch
} <BRANCHES>;
close BRANCHES;
}
} elsif ($ref =~ m/refs\/heads\//) {
if ($ref =~ m/refs\/heads\//) {
print "Detected direct commit to branch.\n";
$branch = $ref;
$branch =~ s/refs\/heads\///;
Expand Down
11 changes: 8 additions & 3 deletions data/gerrit/hooks/ref-updated
Expand Up @@ -7,9 +7,9 @@
# Close stdout, close stderr, redirect stdout to log, redirect stderr to log
#
LOG="/tmp/notify"
exec 1<&-
exec 2<&-
exec 1<>$LOG
#exec 1<&-
#exec 2<&-
exec 1>$LOG
exec 2>&1

PROJECT=""
Expand Down Expand Up @@ -58,6 +58,11 @@ fi
echo "DEBUG: THE UPLOADER_EMAIL is: $UPLOADER_EMAIL"
echo "DEBUG: THE UPLOADER_USERNAME is: $UPLOADER_USERNAME"

if [[ "$REFNAME" =~ "refs/changes/" ]]; then
echo "WARNING: Skipping git changeset ref!"
exit 0
fi

echo "Obtaining lock..."

lockfile=$GIT_DIR/receive.lock
Expand Down

0 comments on commit 4ba8714

Please sign in to comment.