chiark / gitweb /
git-debrebase: Properly reject bare dgit dsc imports
[dgit.git] / git-debrebase
index b61970ce2f57bbef33a8915334a12a73e0272d28..a2a14ca654eaaef818a7081f773d4eac5ba10ed1 100755 (executable)
@@ -61,11 +61,15 @@ sub badusage ($) {
     finish 8;
 }
 
-sub getoptions {
+sub getoptions_main {
     my $m = shift;
     local $SIG{__WARN__}; # GetOptions calls `warn' to print messages
     GetOptions @_ or badusage $m;
 }
+sub getoptions {
+    my $sc = shift;
+    getoptions_main "bad options follow \`git-debrebase $sc'", @_;
+}
 
 sub cfg ($;$) {
     my ($k, $optional) = @_;
@@ -591,6 +595,7 @@ sub keycommits ($;$$$$) {
     my ($anchor, $breakwater);
     my $clogonly;
     my $cl;
+    my $found_pm;
     $fatal //= sub { fail $_[1]; };
     my $x = sub {
        my ($cb, $tagsfx, $mainwhy, $xwhy) = @_;
@@ -630,12 +635,20 @@ sub keycommits ($;$$$$) {
            $breakwater = undef;
        } elsif ($ty eq 'Pseudomerge' or
                 $ty eq 'AddPatches') {
+           my $found_pm = 1;
            $x->($furniture, (lc $ty),
                 "found interchange bureaucracy commit ($ty)"," ($head)");
        } elsif ($ty eq 'DgitImportUnpatched') {
-           $x->($trouble, 'dgitimport',
-                "found dgit dsc import ($head)");
-           return (undef,undef);
+           if ($found_pm) {
+               $x->($trouble, 'dgitimport',
+                    "found dgit dsc import"," ($head)");
+               return (undef,undef);
+           } else {
+               $x->($fatal, 'unprocessable',
+                    "found bare dgit dsc import with no prior history",
+                    " ($head)");
+               return (undef,undef);
+           }
        } else {
            $x->($fatal, 'unprocessable',
                 "found unprocessable commit, cannot cope: $cl->{Why}",
@@ -810,13 +823,12 @@ sub walk ($;$$) {
                next;
            } else {
                # Everything is from this import.  This kind of import
-               # is already in valid breakwater format, with the
-               # patches as commits.
-               printf $report " NoPM" if $report;
-               # last thing we processed will have been the first patch,
-               # if there is one; which is fine, so no need to rewrite
-               # on account of this import
-               $build_start->("ImportOrigin", $cur);
+               # is already nearly in valid breakwater format, with the
+               # patches as commits.  Unfortunately it contains
+               # debian/patches/.
+               printdebug "*** WALK BOMB bare dgit import\n";
+               $cl->{Why} = "bare dgit dsc import";
+               return $bomb->();
            }
            die "$ty ?";
         } else {
@@ -1180,21 +1192,23 @@ sub do_stitch ($;$) {
     stitch($dangling_head, $ffq_prev, $gdrlast, $ffq_prev_commitish, $prose);
 }
 
-sub resolve_upstream_version ($$) {
-    my ($new_upstream, $version) = @_;
+sub upstream_commitish_search ($$) {
+    my ($upstream_version, $tried) = @_;
+    # todo: at some point maybe use git-deborig to do this
+    foreach my $tagpfx ('', 'v', 'upstream/') {
+       my $tag = $tagpfx.(dep14_version_mangle $upstream_version);
+       my $new_upstream = git_get_ref "refs/tags/$tag";
+       push @$tried, $tag;
+       return $new_upstream if length $new_upstream;
+    }
+}
 
-    my $new_upstream_version = "$version";
-    $new_upstream_version =~ s/-.*?$//;;
+sub resolve_upstream_version ($$) {
+    my ($new_upstream, $upstream_version) = @_;
 
     if (!defined $new_upstream) {
        my @tried;
-       # todo: at some point maybe use git-deborig to do this
-       foreach my $tagpfx ('', 'v', 'upstream/') {
-           my $tag = $tagpfx.(dep14_version_mangle $new_upstream_version);
-           $new_upstream = git_get_ref "refs/tags/$tag";
-           last if length $new_upstream;
-           push @tried, $tag;
-       }
+       $new_upstream = upstream_commitish_search $upstream_version, \@tried;
        if (!length $new_upstream) {
            fail "Could not determine appropriate upstream commitish.\n".
                " (Tried these tags: @tried)\n".
@@ -1203,7 +1217,7 @@ sub resolve_upstream_version ($$) {
     }
     $new_upstream = git_rev_parse $new_upstream;
 
-    return ($new_upstream, $new_upstream_version);
+    return $new_upstream;
 }
 
 sub cmd_new_upstream () {
@@ -1223,9 +1237,9 @@ sub cmd_new_upstream () {
     }
 
     my $new_upstream = shift @ARGV;
-    my $new_upstream_version;
-    ($new_upstream, $new_upstream_version) =
-       resolve_upstream_version $new_upstream, $new_version;
+    my $new_upstream_version = upstreamversion  $new_version;
+    $new_upstream =
+       resolve_upstream_version $new_upstream, $new_upstream_version;
 
     record_ffq_auto();
 
@@ -1536,7 +1550,7 @@ sub cmd_status () {
 
 sub cmd_stitch () {
     my $prose = 'stitch';
-    getoptions("bad options follow \`git-debrebase stitch'",
+    getoptions("stitch",
               'prose=s', \$prose);
     badusage "no arguments allowed" if @ARGV;
     do_stitch $prose, 0;
@@ -1600,7 +1614,7 @@ sub make_patches ($) {
 
 sub cmd_make_patches () {
     my $opt_quiet_would_amend;
-    getoptions("bad options follow \`git-debrebase make-patches'",
+    getoptions("make-patches",
               'quiet-would-amend!', \$opt_quiet_would_amend);
     badusage "no arguments allowed" if @ARGV;
     my $old_head = get_head();
@@ -1632,8 +1646,9 @@ sub cmd_convert_from_gbp () {
 
     my ($upstream_spec) = @ARGV;
 
-    my ($upstream, $upstream_version) =
-       resolve_upstream_version($upstream_spec, $version);
+    my $upstream_version = upstreamversion $version;
+    my $upstream =
+       resolve_upstream_version($upstream_spec, $upstream_version);
 
     my $old_head = get_head();
 
@@ -1821,7 +1836,8 @@ sub cmd_downstream_rebase_launder_v0 () {
     }
 }
 
-getoptions("bad options\n",
+getoptions_main
+          ("bad options\n",
           "D+" => \$debuglevel,
           'noop-ok', => \$opt_noop_ok,
           'f=s' => \@snag_force_opts,