X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=blobdiff_plain;f=dgit;h=42fa30688d3d81d1bc36ff98c80900e4719a7153;hp=94b9ab16d287592a9a808d695e7c413524e77011;hb=2f62e59376dcfddcaeff1826f5de91041336a239;hpb=82fe8098ed0b3749821190dfcbb0062947bd024b diff --git a/dgit b/dgit index 94b9ab16..42fa3068 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; @@ -52,6 +53,8 @@ our $initiator_tempdir; our %format_ok = map { $_=>1 } ("1.0","3.0 (native)","3.0 (quilt)"); +our $suite_re = '[-+.0-9a-z]+'; + our (@git) = qw(git); our (@dget) = qw(dget); our (@dput) = qw(dput); @@ -118,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 { @@ -332,7 +344,7 @@ sub printcmd { } sub failedcmd { - { local ($!); printcmd \*STDERR, "$_[0]: failed command:", @_ or die $!; }; + { local ($!); printcmd \*STDERR, "$us: failed command:", @_ or die $!; }; if ($!) { fail "failed to fork/exec: $!"; } elsif (!($? & 0xff)) { @@ -621,6 +633,12 @@ sub git_get_ref ($) { } } +sub must_getcwd () { + my $d = getcwd(); + defined $d or fail "getcwd failed: $!"; + return $d; +} + our %rmad; sub archive_query ($) { @@ -837,6 +855,8 @@ sub check_for_git () { my $r= cmdoutput @cmd; failedcmd @cmd unless $r =~ m/^[01]$/; return $r+0; + } elsif ($how eq 'true') { + return 1; } else { badcfg "unknown git-check \`$how'"; } @@ -849,6 +869,8 @@ sub create_remote_git_repo () { (access_cfg_ssh, access_gituserhost(), "set -e; cd ".access_cfg('git-path').";". " cp -a _template $package.git"); + } elsif ($how eq 'true') { + # nothing to do } else { badcfg "unknown git-create \`$how'"; } @@ -1300,7 +1322,7 @@ type commit tag $tag tagger $authline -$package release $cversion for $clogsuite [dgit] +$package release $cversion for $clogsuite ($csuite) [dgit] END close TO or die $!; @@ -1407,6 +1429,7 @@ sub dopush () { responder_send_file('changes',$changesfile); responder_send_command("param head $head"); + responder_send_command("param csuite $csuite"); my $tfn = sub { ".git/dgit/tag$_[0]"; }; my $tagobjfn; @@ -1430,27 +1453,24 @@ sub dopush () { if (!check_for_git()) { create_remote_git_repo(); } - runcmd_ordryrun @git, qw(push),access_giturl(),"HEAD:".rrref(); + runcmd_ordryrun @git, qw(push),access_giturl(), + "HEAD:".rrref(), "refs/tags/$tag"; runcmd_ordryrun @git, qw(update-ref -m), 'dgit push', lrref(), 'HEAD'; - if (!$we_are_responder) { - if (act_local()) { - rename "$dscpath.tmp",$dscpath or die "$dscfn $!"; - } else { - progress "[new .dsc left in $dscpath.tmp]"; - } - } - if ($we_are_responder) { my $dryrunsuffix = act_local() ? "" : ".tmp"; responder_receive_files('signed-dsc-changes', "$dscpath$dryrunsuffix", "$changesfile$dryrunsuffix"); } else { + if (act_local()) { + rename "$dscpath.tmp",$dscpath or die "$dscfn $!"; + } else { + progress "[new .dsc left in $dscpath.tmp]"; + } sign_changes $changesfile; } - runcmd_ordryrun @git, qw(push),access_giturl(),"refs/tags/$tag"; my $host = access_cfg('upload-host','RETURN-UNDEF'); my @hostarg = defined($host) ? ($host,) : (); runcmd_ordryrun @dput, @hostarg, $changesfile; @@ -1476,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 () { @@ -1722,10 +1757,13 @@ sub i_file_changes { } sub i_want_signed_tag { printdebug Dumper(\%i_param, $i_dscfn); defined $i_param{'head'} && defined $i_dscfn && defined $i_clogp + && defined $i_param{'csuite'} or badproto \*RO, "premature desire for signed-tag"; my $head = $i_param{'head'}; die if $head =~ m/[^0-9a-f]/ || $head !~ m/^../; + die unless $i_param{'csuite'} =~ m/^$suite_re$/; + $csuite = $&; push_parse_dsc $i_dscfn, 'remote dsc', $i_version; my $tagobjfn = @@ -1908,7 +1946,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; @@ -2036,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 \`$_'"; }