[PATCH] filter-branch: strip pgp signature in commit messages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



df062010 (filter-branch: avoid passing commit message through sed)
introduced a regression when filtering gpg signed commits.  The gpgsig
header is multi-line and contains an empty line.  Although the signature
is indented, making the line a whitespace only line, this still results
in $header_line being empty, causing the “skip header lines” loop to
exit.

The rest of the commit object is then re-used as the rewritten commit
message, causing the new message to include the signature of the
original commit.

Signed-off-by: James McCoy <vega.james@xxxxxxxxx>
---
 git-filter-branch.sh     | 14 +++++++++++---
 t/t7003-filter-branch.sh | 14 ++++++++++++++
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 5b3f63d..dd49b13 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -347,10 +347,18 @@ while read commit parents; do
 	fi
 
 	{
-		while read -r header_line && test -n "$header_line"
+		while read -r header_line &&
+			( test -n "$header_line" || test -n "$gpg_signature" )
 		do
-			# skip header lines...
-			:;
+			# skip header lines... but track whether we are in a
+			# PGP signature, since it will have a whitespace only
+			# line which causes $header_line to be empty
+			if [ "${header_line#gpgsig}" != "$header_line" ]; then
+				gpg_signature=1
+			elif test -n "$gpg_signature" &&
+				expr "$header_line" : ".*END PGP" >/dev/null; then
+				gpg_signature=
+			fi
 		done
 		# and output the actual commit message
 		cat
diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
index 855afda..377c648 100755
--- a/t/t7003-filter-branch.sh
+++ b/t/t7003-filter-branch.sh
@@ -2,6 +2,7 @@
 
 test_description='git filter-branch'
 . ./test-lib.sh
+. "$TEST_DIRECTORY/lib-gpg.sh"
 
 test_expect_success 'setup' '
 	test_commit A &&
@@ -292,6 +293,19 @@ test_expect_success 'Tag name filtering strips gpg signature' '
 	test_cmp expect actual
 '
 
+test_expect_success GPG 'Filtering retains message of gpg signed commit' '
+	mkdir gpg &&
+	touch gpg/foo &&
+	git add gpg &&
+	test_tick &&
+	git commit -S -m "Adding gpg" &&
+
+	git log -1 --format="%s" > expect &&
+	git filter-branch -f --msg-filter "cat" &&
+	git log -1 --format="%s" > actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'Tag name filtering allows slashes in tag names' '
 	git tag -m tag-with-slash X/1 &&
 	git cat-file tag X/1 | sed -e s,X/1,X/2, > expect &&
-- 
2.6.1


-- 
James
GPG Key: 4096R/331BA3DB 2011-12-05 James McCoy <vega.james@xxxxxxxxx>
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]