chiark / gitweb /
Print better message for lack of configuration settings.
[dgit.git] / dgit
diff --git a/dgit b/dgit
index 6369856c4d77d498814e4a0237b6738d1795903c..f9e6d1bc7d9443c3c866e45d3cdf81f000a6e9d9 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",
@@ -490,7 +500,8 @@ sub cfg {
        my $dv = $defcfg{$c};
        return $dv if defined $dv;
     }
-    badcfg "need value for one of: @_";
+    badcfg "need value for one of: @_\n".
+       "$us: distro or suite appears not to be (properly) supported";
 }
 
 sub access_basedistro () {
@@ -505,9 +516,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);
        }
@@ -623,6 +635,12 @@ sub git_get_ref ($) {
     }
 }
 
+sub must_getcwd () {
+    my $d = getcwd();
+    defined $d or fail "getcwd failed: $!";
+    return $d;
+}
+
 our %rmad;
 
 sub archive_query ($) {
@@ -1374,13 +1392,17 @@ sub dopush () {
         $dscpath =~ m#^/# ? $dscpath : "../../../$dscpath";
     my ($tree,$dir) = mktree_in_ud_from_only_subdir();
     changedir '../../../..';
-    my @diffcmd = (@git, qw(diff --exit-code), $tree);
+    my $diffopt = $debug>0 ? '--exit-code' : '--quiet';
+    my @diffcmd = (@git, qw(diff), $diffopt, $tree);
     printcmd \*DEBUG,$debugprefix."+",@diffcmd;
     $!=0; $?=0;
-    if (system @diffcmd) {
-       if ($! && $?==256) {
+    my $r = system @diffcmd;
+    if ($r) {
+       if ($r==256) {
            fail "$dscfn specifies a different tree to your HEAD commit;".
-               " perhaps you forgot to build";
+               " perhaps you forgot to build".
+               ($diffopt eq '--exit-code' ? "" :
+                " (run with -D to see full diff output)");
        } else {
            failedcmd @diffcmd;
        }
@@ -1480,7 +1502,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 () {
@@ -1915,7 +1952,7 @@ sub build_source {
        runcmd_ordryrun_local (@dpkgbuildpackage, qw(-us -uc -S)),
            changesopts();
     } else {
-       my $pwd = cmdoutput qw(env - pwd);
+       my $pwd = must_getcwd();
        my $leafdir = basename $pwd;
        changedir "..";
        runcmd_ordryrun_local @dpkgsource, qw(-b --), $leafdir;
@@ -2043,6 +2080,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 \`$_'";
            }