changeset 1108:aae2d15de6af

git_handler: store gpgsig header to maintain commit coherence
author Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
date Tue, 06 Feb 2018 17:04:24 -0800
parents 327d12aeb560
children 21264429a8d4
files hggit/git_handler.py tests/test-git-gpg.t
diffstat 2 files changed, 78 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/git_handler.py	Tue Feb 20 16:21:38 2018 -0800
+++ b/hggit/git_handler.py	Tue Feb 06 17:04:24 2018 -0800
@@ -596,6 +596,8 @@
 
         if 'encoding' in extra:
             commit.encoding = extra['encoding']
+        if 'gpgsig' in extra:
+            commit.gpgsig = extra['gpgsig']
 
         for obj, nodeid in exporter.update_changeset(ctx):
             if obj.id not in self.git.object_store:
@@ -1028,6 +1030,8 @@
 
         if commit.encoding:
             extra['encoding'] = commit.encoding
+        if commit.gpgsig:
+            extra['gpgsig'] = commit.gpgsig
 
         if octopus:
             extra['hg-git'] = 'octopus-done'
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-git-gpg.t	Tue Feb 06 17:04:24 2018 -0800
@@ -0,0 +1,74 @@
+#require gpg
+
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
+  $ export GNUPGHOME="$(mktemp -d)"
+  $ cp -R "$TESTDIR"/gpg/* "$GNUPGHOME"
+
+Start gpg-agent, which is required by GnuPG v2
+
+#if gpg21
+  $ gpg-connect-agent -q --subst /serverpid '/echo ${get serverpid}' /bye \
+  > >> $DAEMON_PIDS
+#endif
+
+and migrate secret keys
+
+#if gpg2
+  $ gpg --no-permission-warning --no-secmem-warning --list-secret-keys \
+  > > /dev/null 2>&1
+#endif
+
+  $ alias gpg='gpg --no-permission-warning --no-secmem-warning --no-auto-check-trustdb'
+
+Set up two identical git repos.
+
+  $ mkdir gitrepo
+  $ cd gitrepo
+  $ git init
+  Initialized empty Git repository in $TESTTMP/gitrepo/.git/
+  $ touch a
+  $ git add a
+  $ git commit -m "initial commit"
+  [master (root-commit) *] initial commit (glob)
+   1 file changed, 0 insertions(+), 0 deletions(-)
+   create mode 100644 a
+  $ cd ..
+  $ git clone gitrepo gitrepo2
+  Cloning into 'gitrepo2'...
+  done.
+
+Add a signed commit to the first clone.
+
+  $ cd gitrepo
+  $ git checkout -b signed
+  Switched to a new branch 'signed'
+  $ touch b
+  $ git add b
+  $ git commit -m "message" -Shgtest
+  [signed *] message (glob)
+   1 file changed, 0 insertions(+), 0 deletions(-)
+   create mode 100644 b
+  $ cd ..
+
+Hg clone it
+
+  $ hg clone gitrepo hgrepo
+  importing git objects into hg
+  updating to branch default
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ cd hgrepo
+  $ hg push ../gitrepo2 -B signed
+  pushing to ../gitrepo2
+  searching for changes
+  adding objects
+  added 1 commits with 1 trees and 0 blobs
+  $ cd ..
+
+Verify the commit
+
+  $ cd gitrepo2
+  $ git show --show-signature signed | grep "Good signature from"
+  gpg: Good signature from "hgtest" [ultimate]