summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2019-07-21 09:31:50 +0100
committerIan Jackson <ijackson@chiark.greenend.org.uk>2019-07-22 16:09:15 +0100
commit4bbb0ea95dcf9be8e26f19424ad3b5269a556783 (patch)
treeb35e76567d1e57197a8200486b3cabb087b503dd
parentf6f6419eca67882b47632875d2ee7163f4d005c7 (diff)
git-debpush: Check that patches are (un)applicable
Closes: #932477 Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
-rwxr-xr-xgit-debpush58
-rw-r--r--git-debpush.1.pod20
-rwxr-xr-xtests/tests/tagupl-baredebian11
3 files changed, 88 insertions, 1 deletions
diff --git a/git-debpush b/git-debpush
index bd0357b..8419375 100755
--- a/git-debpush
+++ b/git-debpush
@@ -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
diff --git a/git-debpush.1.pod b/git-debpush.1.pod
index a554fd5..27b80c9 100644
--- a/git-debpush.1.pod
+++ b/git-debpush.1.pod
@@ -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.
diff --git a/tests/tests/tagupl-baredebian b/tests/tests/tagupl-baredebian
index 764debd..b485abb 100755
--- a/tests/tests/tagupl-baredebian
+++ b/tests/tests/tagupl-baredebian
@@ -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