+ $ENV{'DGIT_DRS_WORK'}= $workrepo;
+ $ENV{'DGIT_DRS_DEST'}= $destrepo;
+ debug " stunt hook set up $prerecv";
+}
+
+sub maybeinstallprospective () {
+ return if $destrepo eq $realdestrepo;
+
+ if (open REJ, "<", "$workrepo/drs-error") {
+ local $/ = undef;
+ my $msg = <REJ>;
+ REJ->error and die $!;
+ print STDERR $msg;
+ exit 1;
+ } else {
+ $!==&ENOENT or die $!;
+ }
+
+ debug " show-ref ($destrepo) ...";
+
+ my $child = open SR, "-|";
+ defined $child or die $!;
+ if (!$child) {
+ chdir $destrepo or die $!;
+ exec qw(git show-ref);
+ die $!;
+ }
+ my %got = qw(tag 0 head 0);
+ while (<SR>) {
+ chomp or die;
+ debug " show-refs| $_";
+ s/^\S*[1-9a-f]\S* (\S+)$/$1/ or die;
+ my $wh =
+ m{^refs/tags/} ? 'tag' :
+ m{^refs/dgit/} ? 'head' :
+ die;
+ die if $got{$wh}++;
+ }
+ $!=0; $?=0; close SR or $?==256 or die "$? $!";
+
+ debug "installprospective ?";
+ die Dumper(\%got)." -- missing refs in new repo"
+ if grep { !$_ } values %got;
+
+ debug "install $destrepo => $realdestrepo";
+ rename $destrepo, $realdestrepo or die $!;
+ remove "$destrepo.lock" or die $!;
+}
+
+sub main__git_receive_pack () {
+ makeworkingclone();
+ setupstunthook();
+ runcmd qw(git receive-pack), $workrepo;
+ maybeinstallprospective();