+sub rcs_test_receive () { #{{{
+ # quick success if the user is trusted
+ my $committer=(getpwuid($<))[0];
+ if (! defined $committer) {
+ error("cannot determine username for $<");
+ }
+ exit 0 if ! ref $config{git_untrusted_committers} ||
+ ! grep { $_ eq $committer } @{$config{git_untrusted_committers}};
+
+ # The wiki may not be the only thing in the git repo.
+ # Determine if it is in a subdirectory by examining the srcdir,
+ # and its parents, looking for the .git directory.
+ my $subdir="";
+ my $dir=$config{srcdir};
+ while (! -d "$dir/.git") {
+ $subdir=IkiWiki::basename($dir)."/".$subdir;
+ $dir=IkiWiki::dirname($dir);
+ if (! length $dir) {
+ error("cannot determine root of git repo");
+ }
+ }
+
+ my @errors;
+ while (<>) {
+ chomp;
+ my ($oldrev, $newrev, $refname) = split(' ', $_, 3);
+
+ # only allow changes to gitmaster_branch
+ if ($refname !~ /^refs\/heads\/\Q$config{gitmaster_branch}\E$/) {
+ push @errors, sprintf(gettext("you are not allowed to change %s"), $refname);
+ }
+
+ foreach my $ci (git_commit_info($oldrev."..".$newrev)) {
+ foreach my $detail (@{ $ci->{'details'} }) {
+ my $file = $detail->{'file'};
+
+ # check that all changed files are in the subdir
+ if (length $subdir &&
+ ! ($file =~ s/^\Q$subdir\E//)) {
+ push @errors, sprintf(gettext("you are not allowed to change %s"), $file);
+ next;
+ }
+
+ if ($detail->{'mode_from'} ne $detail->{'mode_to'}) {
+ push @errors, gettext("you are not allowed to change file modes");
+ }
+
+ if ($detail->{'status'} =~ /^D+\d*/) {
+ # TODO check_canremove
+ }
+ elsif ($detail->{'status'} !~ /^[MA]+\d*$/) {
+ push @errors, "unknown status ".$detail->{'status'};
+ }
+ else {
+ # TODO check_canedit
+ # TODO check_canattach
+ }
+ }
+ }
+ }
+
+ if (@errors) {
+ # TODO clean up objects from failed push
+
+ print STDERR "$_\n" foreach @errors;
+ exit 1;
+ }
+ else {
+ exit 0;
+ }
+} #}}}
+