summaryrefslogtreecommitdiff
path: root/dgit
diff options
context:
space:
mode:
authorIan Jackson <ijackson@chiark.greenend.org.uk>2014-08-03 17:17:19 +0100
committerIan Jackson <ijackson@chiark.greenend.org.uk>2014-08-03 17:31:45 +0100
commit2f62e59376dcfddcaeff1826f5de91041336a239 (patch)
treeeb063f1302cf2acb1dfac27a35959c0145813d86 /dgit
parenta687e0b6a3ac727f4b40f042265093699717251e (diff)
Clone removes destination directory on error. Closes:#736153.
Diffstat (limited to 'dgit')
-rwxr-xr-xdgit28
1 files changed, 28 insertions, 0 deletions
diff --git a/dgit b/dgit
index 8661339..42fa306 100755
--- 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 {
@@ -1486,7 +1496,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 +2074,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 \`$_'";
}