Source

commitsigs / tests / test-commitsigs

#!/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 verifysigs --only-heads > output
    echo "% hg verifysigs --only-heads (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:verifyheadshook
pretxnchangegroup = python:$TESTDIR/../commitsigs.py:verifyallhook
EOF

echo "% commit with pretxncommit hook"
echo "!" >> a.txt
hg commit --config extensions.commitsigs=! -m "No signature" -d '4000 0' 2>&1 \
    | sed 's|:[0-9a-f]\+:|:XXXXXXXXXXXX:|'


echo "% push with pretxnchangegroup hook"
hg clone -q . ../repo2
cd ../repo2
echo "!" >> a.txt
hg commit --config extensions.commitsigs=! -m "No signature" -d '5000 0'
hg push -q 2>&1 | sed 's|:[0-9a-f]\+:|:XXXXXXXXXXXX:|'


cat >> logmsg <<EOF
A long commit message with
trailing whitespace.



EOF

echo >> a.txt
echo "% Commit with trailing whitespace"
hg commit -l logmsg -d '3500 0'

hgverifysigs

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

echo "% unknown scheme"
hg status

true
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.