chiark / gitweb /
Work with wheezy-backports (and keep squeeze-backports working too). Closes:#736524.
[dgit.git] / dgit
diff --git a/dgit b/dgit
index 86613399893cb7915bd9427ff4f70cc874a67909..4b218a3b2c8d46870a8691444f03c90b8610e554 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -44,6 +44,7 @@ our $buildproductsdir = '..';
 our $new_package = 0;
 our $ignoredirty = 0;
 our $noquilt = 0;
+our $rmonerror = 1;
 our $existing_package = 'dpkg';
 our $cleanmode = 'dpkg-source';
 our $changes_since_version;
@@ -120,6 +121,15 @@ sub dscfn ($) {
 our $us = 'dgit';
 our $debugprefix = '';
 
+our @end;
+END { 
+    local ($?);
+    foreach my $f (@end) {
+       eval { $f->(); };
+       warn "$us: cleanup: $@" if length $@;
+    }
+};
+
 sub printdebug { print DEBUG $debugprefix, @_ or die $!; }
 
 sub fail { 
@@ -459,7 +469,7 @@ our %defcfg = ('dgit.default.distro' => 'debian',
               'dgit-distro.debian.sshpsql-dbname' => 'service=projectb',
               'dgit-distro.debian.upload-host' => 'ftp-master', # for dput
               'dgit-distro.debian.mirror' => 'http://ftp.debian.org/debian/',
- 'dgit-distro.debian.backports-quirk' => '%-backports*',
+ 'dgit-distro.debian.backports-quirk' => '(squeeze)-backports*',
  'dgit-distro.debian-backports.mirror' => 'http://backports.debian.org/debian-backports/',
               'dgit-distro.test-dummy.ssh' => "$td/ssh",
               'dgit-distro.test-dummy.username' => "alice",
@@ -505,9 +515,10 @@ sub access_quirk () {
                              'RETURN-UNDEF');
     if (defined $backports_quirk) {
        my $re = $backports_quirk;
-       $re =~ s/[^-0-9a-z_\%*]/\\$&/ig;
+       $re =~ s/[^-0-9a-z_\%*()]/\\$&/ig;
        $re =~ s/\*/.*/g;
-       $re =~ s/\%/([-0-9a-z_]+)/ or badcfg "backports-quirk needs \%";
+       $re =~ s/\%/([-0-9a-z_]+)/
+           or $re =~ m/[()]/ or badcfg "backports-quirk needs \% or ( )";
        if ($isuite =~ m/^$re$/) {
            return ('backports',"$basedistro-backports",$1);
        }
@@ -1486,7 +1497,22 @@ sub cmd_clone {
        badusage "incorrect arguments to dgit clone";
     }
     $dstdir ||= "$package";
+
+    my $cwd_remove;
+    if ($rmonerror && !$dryrun_level) {
+       $cwd_remove= getcwd();
+       unshift @end, sub { 
+           return unless defined $cwd_remove;
+           if (!chdir "$cwd_remove") {
+               return if $!==&ENOENT;
+               die "chdir $cwd_remove: $!";
+           }
+           rmtree($dstdir) or die "remove $dstdir: $!\n";
+       };
+    }
+
     clone($dstdir);
+    $cwd_remove = undef;
 }
 
 sub branchsuite () {
@@ -2049,6 +2075,9 @@ sub parseopts () {
            } elsif (m/^--no-quilt-fixup$/s) {
                push @ropts, $_;
                $noquilt = 1;
+           } elsif (m/^--no-rm-on-error$/s) {
+               push @ropts, $_;
+               $rmonerror = 0;
            } else {
                badusage "unknown long option \`$_'";
            }