chiark / gitweb /
git-debpush: Check that patches are (un)applicable
authorSean Whitton <spwhitton@spwhitton.name>
Sun, 21 Jul 2019 08:31:50 +0000 (09:31 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 22 Jul 2019 15:09:15 +0000 (16:09 +0100)
Closes: #932477
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
git-debpush
git-debpush.1.pod
tests/tests/tagupl-baredebian

index bd0357b5dc3a301979297023efc67dce5fb727e3..841937510b6f1666cafb52dc43cc490cd102d001 100755 (executable)
@@ -121,6 +121,51 @@ check_treesame () {
     fi
 }
 
+check_patches_apply () {
+    local should_match_branch="$1"
+
+    local playground="$(git rev-parse --git-dir)/gdp"
+    local playtree="$playground/apply-patches"
+    local git_apply_rc=0
+
+    rm -rf "$playground"
+    mkdir -p "$playtree"
+    local pwd="$(pwd)"
+    cd "$playtree"
+    "$git_playtree_setup" .
+
+    # checking out the upstream source and then d/patches on top
+    # ensures this check will work for a variety of quilt modes
+    git checkout -b upstream "$upstream_committish"
+    git checkout "$branch_commit" -- debian
+
+    if [ -s "debian/patches/series" ]; then
+        while read patch; do
+            shopt -s extglob; patch="${patch%%?( )#*}"; shopt -u extglob
+            if [ -z "$patch" ]; then continue; fi
+            set +e
+            git apply --index "debian/patches/$patch"
+            git_apply_rc=$?
+            set -e
+            if ! [ $git_apply_rc = 0 ]; then
+                fail_check patches-applicable \
+                           "'git apply' failed to apply patch $patch"
+                break
+            fi
+        done <debian/patches/series
+
+        if $should_match_branch && [ $git_apply_rc = 0 ]; then
+            git commit -q -a -m"commit result of applying all patches"
+            check_treesame HEAD "$branch_commit" ':!debian' \
+                || fail_check patches-applicable \
+                              "applying all patches does not yield $branch"
+        fi
+    fi
+
+    cd "$pwd"
+    rm -rf "$playground"
+}
+
 # **** Parse command line ****
 
 getopt=$(getopt -s bash -o 'nfu:' \
@@ -220,6 +265,9 @@ case "$branch" in
         ;;
 esac
 
+# resolve $branch to a commit
+branch_commit="$(git rev-parse --verify ${branch}^{commit})"
+
 # also check, if the branch does not have its own pushRemote or
 # remote, whether there's a default push remote configured
 remoteconfigs+=(remote.pushDefault)
@@ -342,16 +390,24 @@ if ! [ "x$upstream_tag" = "x" ] \
  "upstream tag $upstream_tag is not an ancestor of $branch; probably a mistake"
 fi
 
-# ---- Upstream tag tree nonidentical
+# ---- Quilt mode-specific checks
 
 case "$quilt_mode" in
     gbp)
         check_treesame "$upstream_tag" "$branch" ':!debian' ':!**.gitignore' \
             || fail_check_upstream_nonidentical
+        check_patches_apply false
         ;;
     unapplied)
         check_treesame "$upstream_tag" "$branch" ':!debian' \
             || fail_check_upstream_nonidentical
+        check_patches_apply false
+        ;;
+    baredebian)
+        check_patches_apply false
+        ;;
+    dpm|nofix)
+        check_patches_apply true
         ;;
 esac
 
index a554fd5695cb245d5c5609fece34cb0cafc309c4..27b80c913246b6454609b554c5f484327141bf70 100644 (file)
@@ -206,6 +206,26 @@ Ignore any differences between the upstream source in the upstream tag
 and the upstream source in the branch to be tagged (this check is only
 run when using B<--quilt=gbp> or B<--quilt=unapplied>).
 
+=item B<patches-applicable>
+
+Ignore any failures of the following two checks:
+
+=over 4
+
+=item
+
+With B<--quilt=gbp>, B<--quilt=unapplied>, B<--quilt=baredebian>,
+B<--quilt=dpm>, and B<--quilt=nofix>, the quilt patches should apply
+cleanly to the upstream source with git-apply(1).
+
+=item
+
+With B<--quilt=dpm> and B<--quilt=nofix>, applying the quilt patches
+to the upstream source should produce exactly the source tree to be
+tagged.
+
+=back
+
 =item B<unreleased>
 
 Permit upload to a suite called UNRELEASED.
index 764debdcb28068d82ecaa568e4008ff4f8ab33b1..b485abb9e108dabc8c11d45a4d90690ffea43aec 100755 (executable)
@@ -17,7 +17,18 @@ t-tagupl-settings
 baredebian-test-minimum
 baredebian-test-core-prepush
 
+
+sed -i '15icorruption' debian/patches/0002-Edit-the-.c-file.patch
+git add debian/patches/0002-Edit-the-.c-file.patch
+git commit -m"corrupt a quilt patch to test the patches-applicable check"
+
 tagname=test-dummy/$v
+
+t-expect-fail "'git apply' failed to apply patch 0002-Edit-the-.c-file.patch ('patches-applicable' check)" \
+t-tagupl-test --baredebian
+
+git reset --hard HEAD~1
+
 t-tagupl-test --baredebian
 
 git branch split.p dgit/dgit/sid # we didn't generate this here