chiark / gitweb /
Clone removes destination directory on error. Closes:#736153.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 3 Aug 2014 16:17:19 +0000 (17:17 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 3 Aug 2014 16:31:45 +0000 (17:31 +0100)
debian/changelog
dgit
dgit.1

index 9a5d4774ef0e6c4a9b3e79bd2ee8ec710c63d17f..6ccbdde8d2a351c4cf42f52669085cbe4dda38f2 100644 (file)
@@ -1,5 +1,8 @@
 dgit (0.22~experimental1) experimental; urgency=low
 
 dgit (0.22~experimental1) experimental; urgency=low
 
+  Bugfixes:
+  * Clone removes destination directory on error.  Closes:#736153.
+
   Minor improvements:
   * Include canonicalised suite name in signed tag message.
   * Mention cross-version dgit rpush incompatibility in manpage.
   Minor improvements:
   * Include canonicalised suite name in signed tag message.
   * Mention cross-version dgit rpush incompatibility in manpage.
diff --git a/dgit b/dgit
index 86613399893cb7915bd9427ff4f70cc874a67909..42fa30688d3d81d1bc36ff98c80900e4719a7153 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -44,6 +44,7 @@ our $buildproductsdir = '..';
 our $new_package = 0;
 our $ignoredirty = 0;
 our $noquilt = 0;
 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;
 our $existing_package = 'dpkg';
 our $cleanmode = 'dpkg-source';
 our $changes_since_version;
@@ -120,6 +121,15 @@ sub dscfn ($) {
 our $us = 'dgit';
 our $debugprefix = '';
 
 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 { 
 sub printdebug { print DEBUG $debugprefix, @_ or die $!; }
 
 sub fail { 
@@ -1486,7 +1496,22 @@ sub cmd_clone {
        badusage "incorrect arguments to dgit clone";
     }
     $dstdir ||= "$package";
        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);
     clone($dstdir);
+    $cwd_remove = undef;
 }
 
 sub branchsuite () {
 }
 
 sub branchsuite () {
@@ -2049,6 +2074,9 @@ sub parseopts () {
            } elsif (m/^--no-quilt-fixup$/s) {
                push @ropts, $_;
                $noquilt = 1;
            } 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 \`$_'";
            }
            } else {
                badusage "unknown long option \`$_'";
            }
diff --git a/dgit.1 b/dgit.1
index 8b1c7f9c9367898c59e74ef2245a1feeaa348fa8..712f36dc80855d8b4e948f180fe4b85680eadbb8 100644 (file)
--- a/dgit.1
+++ b/dgit.1
@@ -398,6 +398,9 @@ instead.  Furthermore, the specified directory will be emptied,
 removed and recreated before dgit starts, rather than removed
 after dgit finishes.  The directory specified must be an absolute
 pathname.
 removed and recreated before dgit starts, rather than removed
 after dgit finishes.  The directory specified must be an absolute
 pathname.
+.TP
+.BI --no-rm-on-error
+Do not delete the destination directory if clone fails.
 .SH WORKFLOW - SIMPLE
 It is always possible with dgit to clone or fetch a package, make
 changes in git (using git-commit) on the suite branch
 .SH WORKFLOW - SIMPLE
 It is always possible with dgit to clone or fetch a package, make
 changes in git (using git-commit) on the suite branch