Source

commitsigs / tests / test-commitsigs

Full commit
#!/bin/sh

"$TESTDIR/hghave" gpg openssl || exit 80

hgverifysigs () {
    hg verifysigs > output
    echo "% hg verifysigs (exit code: $?)"
    sed 's|:[0-9a-f]\+:|:XXXXXXXXXXXX:|' < output
    rm output
}

hg init repo
cd repo
echo "Hello" > a.txt
hg add a.txt
echo "% Commit with no signature"
hg commit -m "Unsigned" -d '1000 0'

cat >> $HGRCPATH <<EOF
[extensions]
commitsigs = $TESTDIR/../commitsigs.py

[commitsigs]
gnupg.flags = --no-permission-warning --no-secmem-warning \
              --homedir $TESTDIR/gpg

EOF

hgverifysigs

echo "World" >> a.txt
echo "% Commit with GnuPG signature"
hg commit -m "GnuPG" -d '2000 0'
hgverifysigs

cat >> $HGRCPATH <<EOF
[commitsigs]
scheme = openssl
openssl.certificate = $TESTDIR/openssl/alice.pem
openssl.capath = $TESTDIR/openssl
EOF

echo "!" >> a.txt
echo "% Commit with OpenSSL signature"
hg commit -m "OpenSSL" -d '3000 0'

hgverifysigs

cat >> .hg/hgrc <<EOF
[hooks]
pretxncommit = python:$TESTDIR/../commitsigs.py:hook
pretxnchangegroup = python:$TESTDIR/../commitsigs.py:hook
EOF

echo "% commit with pretxncommit hook"
echo "!" >> a.txt
hg commit --config extensions.commitsigs=! -m "No signature" -d '4000 0'

cat >> $HGRCPATH <<EOF
[commitsigs]
scheme = x
EOF

echo "% unknown scheme"
hg status

true