forked from mystor/git-revise
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[gpgsign-at-last] Add support for GPG-signed commits (mystor#46)
GPG-sign commits if option -S/--gpg-sign is given, or if configurations revise.gpgSign or commit.gpgSign are set to true. Unlike Git, we do not support passing the key ID as argument. Git's way of accepting this optional argument is a bit weird. It would be awkward to try to support the same with argparse. So it's probably best to use a separate argument for that in future. For now, the key ID is taken from Git configuration (user.signingKey) or the committer signature as fallback. A call of `git-revise COMMIT --gpg-sign` w/o any changes in the index causes creation of GPG commit signatures for all commits since COMMIT. Conversely, if GPG signing is disabled, git-revise will remove the signature, even if the commits were not modified otherwise. So adding/removing a signature is considered a modification, which seems consistent. This logic is applied to all commits in the todo-list for more consistency. The test is a bit large, but the pieces are mostly independenty. I'm not sure if it's worth to have a separate GPG secret key initialization for each test, and I don't know how to share that. Closes # 46 Closes # 73 Co-authored-by: Johannes Altmanninger <aclopte@gmail.com> Signed-off-by: Nicolas Schier <nicolas@fjasle.eu>
- Loading branch information
Showing
6 changed files
with
220 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# pylint: skip-file | ||
|
||
from conftest import * | ||
from subprocess import CalledProcessError | ||
|
||
|
||
def test_gpgsign(repo): | ||
bash("git commit --allow-empty -m 'commit 1'") | ||
assert repo.get_commit("HEAD").gpgsig is None | ||
|
||
bash( | ||
""" | ||
mkdir ~/.gnupg/ | ||
cat > ~/.gnupg/gpg.conf << EOF | ||
pinentry-mode loopback | ||
EOF | ||
name=$(git config user.name) | ||
email=$(git config user.email) | ||
gpg --batch --passphrase "" --quick-gen-key "$name <$email>" >/dev/null 2>&1 | ||
""" | ||
) | ||
|
||
bash("git config commit.gpgSign true") | ||
main(["HEAD"]) | ||
assert ( | ||
repo.get_commit("HEAD").gpgsig is not None | ||
), "git config commit.gpgSign activates GPG signing" | ||
|
||
bash("git config revise.gpgSign false") | ||
main(["HEAD"]) | ||
assert ( | ||
repo.get_commit("HEAD").gpgsig is None | ||
), "git config revise.gpgSign overrides commit.gpgSign" | ||
|
||
main(["HEAD", "--gpg-sign"]) | ||
assert ( | ||
repo.get_commit("HEAD").gpgsig is not None | ||
), "commandline option overrides configuration" | ||
|
||
main(["HEAD", "--no-gpg-sign"]) | ||
assert repo.get_commit("HEAD").gpgsig is None, "long option" | ||
|
||
main(["HEAD", "-S"]) | ||
assert repo.get_commit("HEAD").gpgsig is not None, "short option" | ||
|
||
bash("git config gpg.program false") | ||
try: | ||
main(["HEAD", "--gpg-sign"]) | ||
assert False, "Overridden gpg.program should fail" | ||
except CalledProcessError: | ||
pass | ||
bash("git config --unset gpg.program") | ||
|
||
# Check that we can sign multiple commits. | ||
bash( | ||
""" | ||
git -c commit.gpgSign=false commit --allow-empty -m 'commit 2' | ||
git -c commit.gpgSign=false commit --allow-empty -m 'commit 3' | ||
git -c commit.gpgSign=false commit --allow-empty -m 'commit 4' | ||
""" | ||
) | ||
main(["HEAD~~", "--gpg-sign"]) | ||
assert repo.get_commit("HEAD~~").gpgsig is not None | ||
assert repo.get_commit("HEAD~").gpgsig is not None | ||
assert repo.get_commit("HEAD").gpgsig is not None | ||
|
||
# Check that we can remove signatures from multiple commits. | ||
main(["HEAD~", "--no-gpg-sign"]) | ||
assert repo.get_commit("HEAD~").gpgsig is None | ||
assert repo.get_commit("HEAD").gpgsig is None | ||
|
||
# Check that we add signatures, even if the target commit already has one. | ||
assert repo.get_commit("HEAD~~").gpgsig is not None | ||
main(["HEAD~~", "--gpg-sign"]) | ||
assert repo.get_commit("HEAD~").gpgsig is not None | ||
assert repo.get_commit("HEAD").gpgsig is not None |