Skip to content

Commit 2a118d2

Browse files
committed
filter-repo: don't crash on streams containing gpgsig blocks
In the future we want to preserve commit signatures (see issue #139). To prepare for that, let's teach the fast-export stream parser to recognize and skip `gpgsig` header blocks followed by a `data` block for the signature content. Git >= v2.50.0 can emit such blocks between `committer` and `encoding`/`data`, using for example: `git fast-export --signed-commits=verbatim` Up to two `gpgsig` blocks may appear (one per hash algorithm). Note that no new flags are passed to `git fast-export`, so signatures are still stripped in practice. We only prevent an assertion failure in `_parse_data` if a stream containing `gpgsig` blocks is fed in (e.g. by hand or by a future version of filter-repo). Signed-off-by: Christian Couder <christian.couder@gmail.com>
1 parent c1d8461 commit 2a118d2

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

git-filter-repo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,10 @@ class FastExportParser(object):
13111311
(author_name, author_email, author_date) = \
13121312
(committer_name, committer_email, committer_date)
13131313

1314+
while self._currentline.startswith(b'gpgsig '):
1315+
self._advance_currentline()
1316+
self._parse_data()
1317+
13141318
encoding = None
13151319
if self._currentline.startswith(b'encoding '):
13161320
encoding = self._parse_encoding()

t/t9390-filter-repo-basics.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,54 @@ test_expect_success 'commit hash unchanged if requested' '
380380
)
381381
'
382382

383+
test_expect_success 'commit signatures ignored' '
384+
(
385+
git init commit_signatures &&
386+
cd commit_signatures &&
387+
388+
cat >input <<-\EOF &&
389+
feature done
390+
commit refs/heads/develop
391+
mark :1
392+
author Just Me <just@here.org> 1234567890 -0200
393+
committer Just Me <just@here.org> 1234567890 -0200
394+
data 2
395+
A
396+
397+
commit refs/heads/develop
398+
mark :2
399+
author Just Me <just@here.org> 1234567890 -0200
400+
committer Just Me <just@here.org> 1234567890 -0200
401+
gpgsig sha1 openpgp
402+
data 21
403+
sha1 signature stuff
404+
data 2
405+
B
406+
407+
commit refs/heads/develop
408+
mark :3
409+
author Just Me <just@here.org> 1234567890 -0200
410+
committer Just Me <just@here.org> 1234567890 -0200
411+
gpgsig sha1 openpgp
412+
data 21
413+
sha1 signature stuff
414+
gpgsig sha256 openpgp
415+
data 23
416+
sha256 signature stuff
417+
data 2
418+
C
419+
done
420+
EOF
421+
422+
git fast-import --quiet <input &&
423+
424+
git filter-repo --force &&
425+
test $(git rev-list --count develop) = 3 &&
426+
printf "%s\n" develop develop~ develop~2 | git cat-file --batch >commits &&
427+
! grep "^gpgsig" commits
428+
)
429+
'
430+
383431
test_expect_success 'commit message encoding preserved if requested' '
384432
(
385433
git init commit_message_encoding &&

0 commit comments

Comments
 (0)