chiark / gitweb /
When synthesing a commit from a .dsc from the archive, stop internal git reset from...
[dgit.git] / dgit
diff --git a/dgit b/dgit
index fe1bff5f00035a56df33160485b64c85c347fcff..8404a19c2509021f1b8242bac094dc86d0d6e523 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -64,6 +64,7 @@ our $quilt_mode;
 our $quilt_modes_re = 'linear|smash|auto|nofix|nocheck|gbp|unapplied';
 our $we_are_responder;
 our $initiator_tempdir;
+our $patches_applied_dirtily = 00;
 
 our %format_ok = map { $_=>1 } ("1.0","3.0 (native)","3.0 (quilt)");
 
@@ -101,6 +102,7 @@ our %opts_opt_map = ('dget' => \@dget, # accept for compatibility
                      'dpkg-source' => \@dpkgsource,
                      'dpkg-buildpackage' => \@dpkgbuildpackage,
                      'dpkg-genchanges' => \@dpkggenchanges,
+                     'gbp' => \@gbp,
                      'ch' => \@changesopts,
                      'mergechanges' => \@mergechanges);
 
@@ -1446,7 +1448,7 @@ END
     my $cversion = getfield $clogp, 'Version';
     progress "synthesised git commit from .dsc $cversion";
     if ($lastpush_hash) {
-       runcmd @git, qw(reset --hard), $lastpush_hash;
+       runcmd @git, qw(reset -q --hard), $lastpush_hash;
        runcmd qw(sh -ec), 'dpkg-parsechangelog >>../changelogold.tmp';
        my $oldclogp = parsecontrol('../changelogold.tmp','previous changelog');
        my $oversion = getfield $oldclogp, 'Version';
@@ -2559,7 +2561,7 @@ sub quiltify_tree_sentinelfiles ($) {
 
 sub quiltify_splitbrain_needed () {
     if (!$split_brain) {
-       progress "creating dgit view";
+       progress "dgit view: changes are required...";
        runcmd @git, qw(checkout -q -b dgit-view);
        $split_brain = 1;
     }
@@ -2593,7 +2595,7 @@ sub quiltify_splitbrain ($$$$$$) {
     if ($quilt_mode =~ m/gbp|unapplied/ &&
        ($diffbits->{O2A} & 01)) { # some patches
        quiltify_splitbrain_needed();
-       progress "creating patches-applied version using gbp pq";
+       progress "dgit view: creating patches-applied version using gbp pq";
        runcmd shell_cmd 'exec >/dev/null', @gbp, qw(pq import);
        # gbp pq import creates a fresh branch; push back to dgit-view
        runcmd @git, qw(update-ref refs/heads/dgit-view HEAD);
@@ -2602,7 +2604,7 @@ sub quiltify_splitbrain ($$$$$$) {
     if (($diffbits->{H2O} & 02) && # user has modified .gitignore
        !($diffbits->{O2A} & 02)) { # patches do not change .gitignore
        quiltify_splitbrain_needed();
-       progress "creating patch to represent .gitignore changes";
+       progress "dgit view: creating patch to represent .gitignore changes";
         ensuredir "debian/patches";
        my $gipatch = "debian/patches/auto-gitignore";
        open GIPATCH, ">>", "$gipatch" or die "$gipatch: $!";
@@ -2642,7 +2644,7 @@ END
     runcmd @git, qw(update-ref -m), $cachekey, "refs/$splitbraincache",
        $dgitview;
 
-    progress "created dgit view (commit id $dgitview)";
+    progress "dgit view: created (commit id $dgitview)";
 
     changedir '.git/dgit/unpack/work';
 }
@@ -2948,7 +2950,7 @@ sub quilt_fixup_singlepatch ($$$) {
 sub quilt_fixup_multipatch ($$$) {
     my ($clogp, $headref, $upstreamversion) = @_;
 
-    progress "starting quiltify (multiple patches, $quilt_mode mode)";
+    progress "examining quilt state (multiple patches, $quilt_mode mode)";
 
     # Our objective is:
     #  - honour any existing .pc in case it has any strangeness
@@ -3053,13 +3055,15 @@ END
     }
 
     my $debtar= srcfn $fakeversion,'.debian.tar.gz';
-    runcmd qw(env GZIP=-1 tar -zcf), "./$debtar", qw(-C ../../..), @files;
+    runcmd qw(env GZIP=-1n tar -zcf), "./$debtar", qw(-C ../../..), @files;
 
     $dscaddfile->($debtar);
     close $fakedsc or die $!;
 
     my $splitbrain_cachekey;
     if (quiltmode_splitbrain()) {
+       progress
+ "dgit: split brain (separate dgit view) may needed (--quilt=$quilt_mode).";
        # we look in the reflog of dgit-intern/quilt-cache
        # we look for an entry whose message is the key for the cache lookup
        my @cachekey = (qw(dgit), $our_version);
@@ -3101,13 +3105,12 @@ END
            my $cachehit = $1;
            quilt_fixup_mkwork($headref);
            if ($cachehit ne $headref) {
-               progress "quilt fixup ($quilt_mode mode) found cached tree";
+               progress "dgit view: found cached (commit id $cachehit)";
                runcmd @git, qw(checkout -q -b dgit-view), $cachehit;
                $split_brain = 1;
                return;
            }
-           progress "quilt fixup ($quilt_mode mode)".
-             " found cached indication that no changes needed";
+           progress "dgit view: found cached, no changes required";
            return;
        }
        die $! if GC->error;
@@ -3202,6 +3205,7 @@ END
        return;
     }
 
+    progress "starting quiltify (multiple patches, $quilt_mode mode)";
     quiltify($clogp,$headref,$oldtiptree,\@failsuggestion);
 
     if (!open P, '>>', ".pc/applied-patches") {
@@ -3236,6 +3240,29 @@ sub quilt_fixup_editor () {
     exit 0;
 }
 
+sub maybe_apply_patches_dirtily () {
+    return unless $quilt_mode =~ m/gbp|unapplied/;
+    print STDERR <<END or die $!;
+
+dgit: Building, or cleaning with rules target, in patches-unapplied tree.
+dgit: Have to apply the patches - making the tree dirty.
+dgit: (Consider specifying --clean=git and (or) using dgit sbuild.)
+
+END
+    $patches_applied_dirtily = 01;
+    $patches_applied_dirtily |= 02 unless stat_exists '.pc';
+    runcmd qw(dpkg-source --before-build .);
+}
+
+sub maybe_unapply_patches_again () {
+    progress "dgit: Unapplying patches again to tidy up the tree."
+       if $patches_applied_dirtily;
+    runcmd qw(dpkg-source --after-build .)
+       if $patches_applied_dirtily & 01;
+    rmtree '.pc'
+       if $patches_applied_dirtily & 02;
+}
+
 #----- other building -----
 
 our $clean_using_builder;
@@ -3247,8 +3274,10 @@ our $clean_using_builder;
 sub clean_tree () {
     return if $clean_using_builder;
     if ($cleanmode eq 'dpkg-source') {
+       maybe_apply_patches_dirtily();
        runcmd_ordryrun_local @dpkgbuildpackage, qw(-T clean);
     } elsif ($cleanmode eq 'dpkg-source-d') {
+       maybe_apply_patches_dirtily();
        runcmd_ordryrun_local @dpkgbuildpackage, qw(-d -T clean);
     } elsif ($cleanmode eq 'git') {
        runcmd_ordryrun_local @git, qw(clean -xdf);
@@ -3270,6 +3299,7 @@ sub cmd_clean () {
     badusage "clean takes no additional arguments" if @ARGV;
     notpushing();
     clean_tree();
+    maybe_unapply_patches_again();
 }
 
 sub build_prep () {
@@ -3391,8 +3421,10 @@ sub cmd_build {
     }
     if ($wantsrc < 2) {
        push @dbp, changesopts_version();
+       maybe_apply_patches_dirtily();
        runcmd_ordryrun_local @dbp;
     }
+    maybe_unapply_patches_again();
     printdone "build successful\n";
 }
 
@@ -3423,8 +3455,10 @@ sub cmd_gbp_build {
            push @cmd, "--git-debian-branch=".lbranch();
        }
        push @cmd, changesopts();
+       maybe_apply_patches_dirtily();
        runcmd_ordryrun_local @cmd, @ARGV;
     }
+    maybe_unapply_patches_again();
     printdone "build successful\n";
 }
 sub cmd_git_build { cmd_gbp_build(); } # compatibility with <= 1.0
@@ -3451,9 +3485,11 @@ sub build_source {
     }
     $dscfn = dscfn($version);
     if ($our_cleanmode eq 'dpkg-source') {
+       maybe_apply_patches_dirtily();
        runcmd_ordryrun_local @dpkgbuildpackage, qw(-us -uc -S),
            changesopts();
     } elsif ($our_cleanmode eq 'dpkg-source-d') {
+       maybe_apply_patches_dirtily();
        runcmd_ordryrun_local @dpkgbuildpackage, qw(-us -uc -S -d),
            changesopts();
     } else {
@@ -3490,6 +3526,7 @@ sub build_source {
 sub cmd_build_source {
     badusage "build-source takes no additional arguments" if @ARGV;
     build_source();
+    maybe_unapply_patches_again();
     printdone "source built, results in $dscfn and $sourcechanges";
 }
 
@@ -3532,6 +3569,7 @@ sub cmd_sbuild {
            rename "$cf", "$cf.inmulti" or fail "$cf\{,.inmulti}: $!";
        }
     }
+    maybe_unapply_patches_again();
     printdone "build successful, results in $multichanges\n" or die $!;
 }