chiark / gitweb /
Test suite: Explicitly configure user.name and user.email
[dgit.git] / dgit
diff --git a/dgit b/dgit
index 87419c266574709d8fc02b420ded39ae2aba6f3e..8e72b2aac1c93535faaaf29173e2f46e0b281c67 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -5276,12 +5276,29 @@ sub cmd_quilt_fixup {
 }
 
 sub cmd_import_dsc {
+    my $needsig = 0;
+
+    while (@ARGV) {
+       last unless $ARGV[0] =~ m/^-/;
+       $_ = shift @ARGV;
+       last if m/^--?$/;
+       if (m/^--require-valid-signature$/) {
+           $needsig = 1;
+       } else {
+           badusage "unknown dgit import-dsc sub-option \`$_'";
+       }
+    }
+
     badusage "usage: dgit import-dsc .../PATH/TO/.DSC BRANCH" unless @ARGV==2;
     my ($dscfn, $dstbranch) = @ARGV;
 
     badusage "dry run makes no sense with import-dsc" unless act_local();
 
-    my $info = "$dscfn";
+    my $force = $dstbranch =~ s/^\+//   ? +1 :
+               $dstbranch =~ s/^\.\.// ? -1 :
+                                           0;
+    my $info = $force ? " $&" : '';
+    $info = "$dscfn$info";
 
     my $specbranch = $dstbranch;
     $dstbranch = "refs/heads/$dstbranch" unless $dstbranch =~ m#^refs/#;
@@ -5294,10 +5311,31 @@ sub cmd_import_dsc {
     fail "$dstbranch is checked out - will not update it"
        if defined $chead and $chead eq $dstbranch;
 
+    my $oldhash = git_get_ref $dstbranch;
+
     open D, "<", $dscfn or fail "open import .dsc ($dscfn): $!";
     $dscdata = do { local $/ = undef; <D>; };
     D->error and fail "read $dscfn: $!";
     close C;
+
+    # we don't normally need this so import it here
+    use Dpkg::Source::Package;
+    my $dp = new Dpkg::Source::Package filename => $dscfn,
+       require_valid_signature => $needsig;
+    {
+       local $SIG{__WARN__} = sub {
+           print STDERR $_[0];
+           return unless $needsig;
+           fail "import-dsc signature check failed";
+       };
+       if (!$dp->is_signed()) {
+           warn "$us: warning: importing unsigned .dsc\n";
+       } else {
+           my $r = $dp->check_signature();
+           die "->check_signature => $r" if $needsig && $r;
+       }
+    }
+
     parse_dscdata();
 
     my $dgit_commit = $dsc->{$ourdscfield[0]};
@@ -5315,6 +5353,13 @@ Your git tree does not have that object.  Try `git fetch' from a
 plausible server (browse.dgit.d.o? alioth?), and try the import-dsc again.
 END
        }
+       if ($oldhash && !is_fast_fwd $oldhash, $dgit_commit) {
+           if ($force > 0) {
+               progress "Not fast forward, forced update.";
+           } else {
+               fail "Not fast forward to $dgit_commit";
+           }
+       }
        @cmd = (@git, qw(update-ref -m), "dgit import-dsc (Dgit): $info",
                $dstbranch, $dgit_commit);
        runcmd @cmd;
@@ -5322,6 +5367,13 @@ END
        return 0;
     }
 
+    fail <<END
+Branch $dstbranch already exists
+Specify ..$specbranch for a pseudo-merge, binding in existing history
+Specify  +$specbranch to overwrite, discarding existing history
+END
+       if $oldhash && !$force;
+
     $package = getfield $dsc, 'Source';
     my @dfi = dsc_files_info();
     foreach my $fi (@dfi) {
@@ -5347,8 +5399,29 @@ END
     my @mergeinputs = generate_commits_from_dsc();
     die unless @mergeinputs == 1;
 
+    my $newhash = $mergeinputs[0]{Commit};
+
+    if ($oldhash) {
+       if ($force > 0) {
+           progress "Import, forced update - synthetic orphan git history.";
+       } elsif ($force < 0) {
+           progress "Import, merging.";
+           my $tree = cmdoutput @git, qw(rev-parse), "$newhash:";
+           my $version = getfield $dsc, 'Version';
+           $newhash = make_commit_text <<END;
+tree $tree
+parent $newhash
+parent $oldhash
+
+Merge $package ($version) import into $dstbranch
+END
+       } else {
+           die; # caught earlier
+       }
+    }
+
     my @cmd = (@git, qw(update-ref -m), "dgit import-dsc: $info",
-              $dstbranch, $mergeinputs[0]{Commit});
+              $dstbranch, $newhash);
     runcmd @cmd;
     progress "dgit: import-dsc results are in in git ref $dstbranch";
 }