@matheusbsbs / matheus-bagliano / commits / cdf63284de
Fork 0

git-cvsserver runs hooks/post-receive

git-cvsserver just did the following: (1) run hooks/update (2) commit if hooks/update passed This commit simply adds: (3) run hooks/post-receive Also, there are a few grammar cleanups and consistency improvements. Signed-off-by: Michael Witten <mfwitten@mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Witten committed Nov 23, 2007 at 04:12 UTC cdf63284de7bd9ca5439c76ecbd820551ae506c8
1 file changed +20 -7
git-cvsserver.perl
+20 -7
@@ -1211,13 +1211,13 @@ sub req_ci
1211
1212 chdir $tmpdir;
1213
1214 - # populate the temporary index based
1214 + # populate the temporary index
1215 system("git-read-tree", $parenthash);
1216 unless ($? == 0)
1217 {
1218 die "Error running git-read-tree $state->{module} $file_index $!";
1219 }
1220 - $log->info("Created index '$file_index' with for head $state->{module} - exit status $?");
1220 + $log->info("Created index '$file_index' for head $state->{module} - exit status $?");
1221
1222 my @committedfiles = ();
1223 my %oldmeta;
@@ -1237,7 +1237,7 @@ sub req_ci
1237
1238 my ( $filepart, $dirpart ) = filenamesplit($filename);
1239
1240 - # do a checkout of the file if it part of this tree
1240 + # do a checkout of the file if it is part of this tree
1241 if ($wrev) {
1242 system('git-checkout-index', '-f', '-u', $filename);
1243 unless ($? == 0) {
@@ -1324,11 +1324,11 @@ sub req_ci
1324 exit;
1325 }
1326
1327 - # Check that this is allowed, just as we would with a receive-pack
1328 - my @cmd = ( $ENV{GIT_DIR}.'hooks/update', "refs/heads/$state->{module}",
1327 + ### Emulate git-receive-pack by running hooks/update
1328 + my @hook = ( $ENV{GIT_DIR}.'hooks/update', "refs/heads/$state->{module}",
1329 $parenthash, $commithash );
1330 - if( -x $cmd[0] ) {
1331 - unless( system( @cmd ) == 0 )
1330 + if( -x $hook[0] ) {
1331 + unless( system( @hook ) == 0 )
1332 {
1333 $log->warn("Commit failed (update hook declined to update ref)");
1334 print "error 1 Commit failed (update hook declined)\n";
@@ -1337,6 +1337,7 @@ sub req_ci
1337 }
1338 }
1339
1340 + ### Update the ref
1341 if (system(qw(git update-ref -m), "cvsserver ci",
1342 "refs/heads/$state->{module}", $commithash, $parenthash)) {
1343 $log->warn("update-ref for $state->{module} failed.");
@@ -1344,6 +1345,18 @@ sub req_ci
1345 exit;
1346 }
1347
1348 + ### Emulate git-receive-pack by running hooks/post-receive
1349 + my $hook = $ENV{GIT_DIR}.'hooks/post-receive';
1350 + if( -x $hook ) {
1351 + open(my $pipe, "| $hook") || die "can't fork $!";
1352 +
1353 + local $SIG{PIPE} = sub { die 'pipe broke' };
1354 +
1355 + print $pipe "$parenthash $commithash refs/heads/$state->{module}\n";
1356 +
1357 + close $pipe || die "bad pipe: $! $?";
1358 + }
1359 +
1360 $updater->update();
1361
1362 # foreach file specified on the command line ...