From patchwork Thu Dec 13 21:22:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro X-Patchwork-Id: 10729941 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BF02A13AF for ; Thu, 13 Dec 2018 21:23:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B191C2CBCF for ; Thu, 13 Dec 2018 21:23:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A56632CBF9; Thu, 13 Dec 2018 21:23:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D2072CBCF for ; Thu, 13 Dec 2018 21:23:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726470AbeLMVXK (ORCPT ); Thu, 13 Dec 2018 16:23:10 -0500 Received: from mail-qt1-f193.google.com ([209.85.160.193]:38093 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726401AbeLMVXK (ORCPT ); Thu, 13 Dec 2018 16:23:10 -0500 Received: by mail-qt1-f193.google.com with SMTP id p17so3912146qtl.5 for ; Thu, 13 Dec 2018 13:23:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XvcHjR6uv5s48Mq1lv4ARXg/Ttrd3VQhcUKmNT61iWU=; b=MmxVNutp7GLulRGlNoWJ3LDb6bs4NzjzIsehT50fOEY48PB4tXS5xCNQgdvQ/Nx2C/ 6tA2Sk72ownSwwaF256rQUsttG79wpa1piKsZxSYnvtOUHl+JJ83HoHw6FGhNWTyVK6i D1odqkLpWWkYcbyFYYh+qxyHgmWYr++Ia77EsMXvTt/i8D1x0poBA6/LNUgw5NTedy6f 1ckep9PL4HKljtgUOR1p6ldVMH5WU/wiolDhTDpra+Z3UpzrKAaVCQAyvd9k4JjNLmrW zkQgQ/GX/S7GwUu9WXl/M5fJfRbVKfsNFGkQS8ZARcjl7diBcPwSZP05tF70L2RaqW0q byFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XvcHjR6uv5s48Mq1lv4ARXg/Ttrd3VQhcUKmNT61iWU=; b=m/cSgeFMgdyiUqSmj/lIdx6XOs7OHhPWUfwtihRVXpoEomxaiMf5d1J0Amt0IPAI0s OlnD2hyoaYfe7ZJrcr1b69t54C1myHf+X769Km1qcYlmSuI2w56zR3mjwTvJPwAZSXag drQtFZATrp4do7SzgtvtpENHUuynjXdwLcEwX37vyoN2pMk2bbL2nG8w0j4PRyg5/Thf nbur6OIqUB6z8nBP+iiTxbuRxGPa8ud/4PCvPfFRKrN/jMR8jsh4BIgvqw9GCLL/tOuT 6ExW5npR2Ylrli2IFR+ZItoJkBGN34iQnY/gA6w/mmTfOoVb/HV8323fetzXZoac61ea oZvA== X-Gm-Message-State: AA+aEWYgv/dBr2D5TSBqvZzgErKQDSnWjUXLr8mu3V4BFE52RUzwOcVP wjU+huXdpTOUx219bsCi5TZ/Zu6a X-Google-Smtp-Source: AFSGD/UcHLFDGuP6GBZrsi379w8YB8VsxegAVDzNPrCyI2F93mSkUwO8kJSC9WksAiG5Psa69dE21g== X-Received: by 2002:a05:6214:18e:: with SMTP id q14mr393337qvr.173.1544736188342; Thu, 13 Dec 2018 13:23:08 -0800 (PST) Received: from localhost.localdomain ([142.154.219.74]) by smtp.gmail.com with ESMTPSA id f13sm1552840qkm.52.2018.12.13.13.23.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Dec 2018 13:23:07 -0800 (PST) From: John Passaro To: git@vger.kernel.org Cc: gitster@pobox.com, alex.crezoff@gmail.com, peff@peff.net, mgorny@gentoo.org, John Passaro Subject: [PATCH 1/4] pretty: expose raw commit signature Date: Thu, 13 Dec 2018 16:22:53 -0500 Message-Id: <20181213212256.48122-2-john.a.passaro@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181213212256.48122-1-john.a.passaro@gmail.com> References: <20181213212256.48122-1-john.a.passaro@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add new pretty-format placeholders %GR and %G+ to support inspecting gpgsig commit header in pretty format, even if GPG is not available. Signed-off-by: John Passaro --- Documentation/pretty-formats.txt | 2 ++ pretty.c | 36 ++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index 417b638cd8..582454a4f7 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -142,6 +142,8 @@ The placeholders are: ifndef::git-rev-list[] - '%N': commit notes endif::git-rev-list[] +- '%GR': contents of the commits signature (blank when unsigned) +- '%G+': "Y" if the commit is signed, "N" otherwise - '%GG': raw verification message from GPG for a signed commit - '%G?': show "G" for a good (valid) signature, "B" for a bad signature, diff --git a/pretty.c b/pretty.c index b83a3ecd23..d142b457b5 100644 --- a/pretty.c +++ b/pretty.c @@ -768,6 +768,9 @@ struct format_commit_context { unsigned commit_header_parsed:1; unsigned commit_message_parsed:1; struct signature_check signature_check; + unsigned signature_checked:2; + struct strbuf signature; + struct strbuf signature_payload; enum flush_type flush_type; enum trunc_type truncate; const char *message; @@ -1228,8 +1231,30 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ } if (placeholder[0] == 'G') { - if (!c->signature_check.result) - check_commit_signature(c->commit, &(c->signature_check)); + if (!c->signature_checked) { + parse_signed_commit(c->commit, &(c->signature_payload), &(c->signature)); + c->signature_checked = 1; + } + switch (placeholder[1]) { + case 'R': + strbuf_addbuf(sb, &(c->signature)); + break; + case '+': + strbuf_addch(sb, c->signature.len ? 'Y' : 'N'); + break; + default: + goto do_signature_check; + } + return 2; + +do_signature_check: + if (c->signature_checked < 2) { + if (c->signature.len) + check_signature(c->signature_payload.buf, c->signature_payload.len, + c->signature.buf, c->signature.len, + &(c->signature_check)); + c->signature_checked = 2; + } switch (placeholder[1]) { case 'G': if (c->signature_check.gpg_output) @@ -1246,6 +1271,9 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ case 'Y': case 'R': strbuf_addch(sb, c->signature_check.result); + break; + case 0: // i.e. no signature so we never ran the check + strbuf_addch(sb, 'N'); } break; case 'S': @@ -1527,6 +1555,8 @@ void format_commit_message(const struct commit *commit, context.commit = commit; context.pretty_ctx = pretty_ctx; context.wrap_start = sb->len; + strbuf_init(&context.signature, 0); + strbuf_init(&context.signature_payload, 0); /* * convert a commit message to UTF-8 first * as far as 'format_commit_item' assumes it in UTF-8 @@ -1556,6 +1586,8 @@ void format_commit_message(const struct commit *commit, strbuf_attach(sb, out, outsz, outsz + 1); } + strbuf_release(&context.signature); + strbuf_release(&context.signature_payload); free(context.commit_encoding); unuse_commit_buffer(commit, context.message); } From patchwork Thu Dec 13 21:22:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro X-Patchwork-Id: 10729943 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E18D96C5 for ; Thu, 13 Dec 2018 21:23:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D17242CBCF for ; Thu, 13 Dec 2018 21:23:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2C962CBF9; Thu, 13 Dec 2018 21:23:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E6FA2CBCF for ; Thu, 13 Dec 2018 21:23:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726533AbeLMVXS (ORCPT ); Thu, 13 Dec 2018 16:23:18 -0500 Received: from mail-qk1-f175.google.com ([209.85.222.175]:41849 "EHLO mail-qk1-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726401AbeLMVXS (ORCPT ); Thu, 13 Dec 2018 16:23:18 -0500 Received: by mail-qk1-f175.google.com with SMTP id 189so2045347qkj.8 for ; Thu, 13 Dec 2018 13:23:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fAYvLtf3VJvJ1Ihji1kTezPQvD1wgjn9L/1A5XuVHDM=; b=idZ1giwdlY8BRlM6/3pdIWB9ofi8nR+tzolyhpxq9eMpZG4toCJxCeRCoO0RvQJKb/ Ehqi1F7oqDBCctUUUY548VMTGiOfnZQsgx19Lr5oRfgDZMayDfOcT//szimagQTObh7N N9Zv+rAUNY8QsAK0lKXSL66WrBg8EfQn3TGm5N5BOVXTwNJW3+slp5R9bxtPjb4jLVsO o7gbyTu+B/fO+MiBoZQURzbhrz+ExvSQnOLjTxCeJz8Q2mmjmtRsqgpTv51JPkftciaB mrY5ojMmJaNil07DgVptHB3rhjpXZ+NpF0xkCRNpOUD32XbbKvEuU8/zdwu/hywPKtsy 2KaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fAYvLtf3VJvJ1Ihji1kTezPQvD1wgjn9L/1A5XuVHDM=; b=Yxcxl+nTmnVj4mAvZerF6Mr+UTgU2SSUUdwe9XTSlzlDuYNXCUrYj0RFEcol157t1N wcPlx2CmSe/Y2KWXyHdtuxaABQzEA+hYFdvJwbiBuEmcQtkgFYBZ5ej+LprIx95nOJ4d aeeMaIozxWBE7l3MA/zu8+tHL21zP6RWB43PGU9zE7f1XqIiuJh2J5IOHtw0cWPtWXO2 UOAG5bxd0IadTEDLPuovGLW4Zwl0+00qFQl2UBdkHI0NF5oLuJ36lFiNJexBqhN5eWqr E3HFrBvfbMNA95Kpwrp8woUAhSqt1OIOe8E2QpIrZZV7EAosWL5KSdjYRI5OEnW6wodO FLwg== X-Gm-Message-State: AA+aEWbQjNRkgqi77l/XUwAMIhRPPdqjTTKgvGdiM0H4+3IM/KeyQ2sP coc7dLtP9PcbaR7ofE4nrwvGovmf X-Google-Smtp-Source: AFSGD/W2ot2Xlm20eij8/ehUGp2RR00hW79ZPhOJPH8UtV7S5J1BSMsHnTK/lLWVaMd3zYwyTt2Ojw== X-Received: by 2002:a37:ac05:: with SMTP id e5mr418904qkm.102.1544736197035; Thu, 13 Dec 2018 13:23:17 -0800 (PST) Received: from localhost.localdomain ([142.154.219.74]) by smtp.gmail.com with ESMTPSA id f13sm1552840qkm.52.2018.12.13.13.23.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Dec 2018 13:23:16 -0800 (PST) From: John Passaro To: git@vger.kernel.org Cc: gitster@pobox.com, alex.crezoff@gmail.com, peff@peff.net, mgorny@gentoo.org, John Passaro Subject: [PATCH 2/4] t/t7510-signed-commit.sh: test new placeholders Date: Thu, 13 Dec 2018 16:22:54 -0500 Message-Id: <20181213212256.48122-3-john.a.passaro@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181213212256.48122-1-john.a.passaro@gmail.com> References: <20181213212256.48122-1-john.a.passaro@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Test that %GR output ("Raw" contents of "gpgsig" header) looks like ASCII-armored GPG signature. Test %G+ (Y/N for presence/absence of "gpgsig" header) by adding it to existing format tests for signed commits. Signed-off-by: John Passaro --- t/t7510-signed-commit.sh | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/t/t7510-signed-commit.sh b/t/t7510-signed-commit.sh index 86d3f93fa2..aff6b1eb3a 100755 --- a/t/t7510-signed-commit.sh +++ b/t/t7510-signed-commit.sh @@ -177,8 +177,9 @@ test_expect_success GPG 'show good signature with custom format' ' C O Mitter 73D758744BE721698EC54E8713B6F51ECDDE430D 73D758744BE721698EC54E8713B6F51ECDDE430D + Y EOF - git log -1 --format="%G?%n%GK%n%GS%n%GF%n%GP" sixth-signed >actual && + git log -1 --format="%G?%n%GK%n%GS%n%GF%n%GP%n%G+" sixth-signed >actual && test_cmp expect actual ' @@ -189,8 +190,9 @@ test_expect_success GPG 'show bad signature with custom format' ' C O Mitter + Y EOF - git log -1 --format="%G?%n%GK%n%GS%n%GF%n%GP" $(cat forged1.commit) >actual && + git log -1 --format="%G?%n%GK%n%GS%n%GF%n%GP%n%G+" $(cat forged1.commit) >actual && test_cmp expect actual ' @@ -201,8 +203,9 @@ test_expect_success GPG 'show untrusted signature with custom format' ' Eris Discordia F8364A59E07FFE9F4D63005A65A0EEA02E30CAD7 D4BE22311AD3131E5EDA29A461092E85B7227189 + Y EOF - git log -1 --format="%G?%n%GK%n%GS%n%GF%n%GP" eighth-signed-alt >actual && + git log -1 --format="%G?%n%GK%n%GS%n%GF%n%GP%n%G+" eighth-signed-alt >actual && test_cmp expect actual ' @@ -213,8 +216,9 @@ test_expect_success GPG 'show unknown signature with custom format' ' + Y EOF - GNUPGHOME="$GNUPGHOME_NOT_USED" git log -1 --format="%G?%n%GK%n%GS%n%GF%n%GP" eighth-signed-alt >actual && + GNUPGHOME="$GNUPGHOME_NOT_USED" git log -1 --format="%G?%n%GK%n%GS%n%GF%n%GP%n%G+" eighth-signed-alt >actual && test_cmp expect actual ' @@ -225,11 +229,27 @@ test_expect_success GPG 'show lack of signature with custom format' ' + N EOF - git log -1 --format="%G?%n%GK%n%GS%n%GF%n%GP" seventh-unsigned >actual && + git log -1 --format="%G?%n%GK%n%GS%n%GF%n%GP%n%G+" seventh-unsigned >actual && test_cmp expect actual ' +test_expect_success GPG 'show lack of raw signature with custom format' ' + git log -1 --format=format:"%GR" seventh-unsigned > actual && + test_must_be_empty actual +' + +test_expect_success GPG 'show raw signature with custom format' ' + git log -1 --format=format:"%GR" sixth-signed >output && + cat output && + head -n1 output | grep -q "^---*BEGIN PGP SIGNATURE---*$" && + sed 1d output | grep -q "^$" && + sed "1,/^$/d" output | grep -q "^[a-zA-Z0-9+/][a-zA-Z0-9+/=]*$" && + tail -n2 output | head -n1 | grep -q "^=[a-zA-Z0-9+/][a-zA-Z0-9+/=]*$" && + tail -n1 output | grep -q "^---*END PGP SIGNATURE---*$" +' + test_expect_success GPG 'log.showsignature behaves like --show-signature' ' test_config log.showsignature true && git show initial >actual && From patchwork Thu Dec 13 21:22:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro X-Patchwork-Id: 10729945 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9DD22112E for ; Thu, 13 Dec 2018 21:23:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E5C42C9CB for ; Thu, 13 Dec 2018 21:23:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8270B2CBEC; Thu, 13 Dec 2018 21:23:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E41DF2C9CB for ; Thu, 13 Dec 2018 21:23:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726604AbeLMVXV (ORCPT ); Thu, 13 Dec 2018 16:23:21 -0500 Received: from mail-qt1-f194.google.com ([209.85.160.194]:42347 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726401AbeLMVXV (ORCPT ); Thu, 13 Dec 2018 16:23:21 -0500 Received: by mail-qt1-f194.google.com with SMTP id d19so3886210qtq.9 for ; Thu, 13 Dec 2018 13:23:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l8ZtC+Vklu0LYJXVdPqVlVmwV0emdImPq+OzgdOX1qI=; b=BOM3ClCeUtO1QxwZOeNjtnajFFOP+NQf9UO4shKnfL87pcrr/UZVfkvzidHLGi/5sQ WQcVmnKfJpg0NmkyNkM8CT3xlW4yPaAoPWeEpH8kTjVpyN1jQEXeM0yXVJyaylb8k2jB 1WHo8/8cLEzW7zGuH1iUOol6nau3QYMWSgj+gxAIcLFBMI521sJuzcpAjFCjgZ0EPUlq LyYZVRD4wcWQT/12UfhIcPneeeaNAZTFJyVnVhwI/Qcq8KaW1x3O71whBG0NfT3/Ze5a Qa2gb1Nt/+f/uE504enaPQPdfdo26ABk/1fI39SX9KpEukCVJJ2HJpvTt4YSyAaBrSJU lY6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=l8ZtC+Vklu0LYJXVdPqVlVmwV0emdImPq+OzgdOX1qI=; b=sX/LJ3pNRiyW8lS3Q5F7aOSz/gVlyT2Zebmj1Yz4uleIbaCyF8vHDtFvBt7IaowpMe GwWLEEmK0rIE28nuOsW8QIwih95FT3vqZKQN1jlQigwykcT/j5UG1HQAGAikriXfEVFM UCw3a9Mi/s9s/gB2wiC0BDVjZmt+U9CF65YoMV6qS3H/DJB/ECC7mSdzPeV2FFg4InJK nSVC4Ir3eCUXEs00ysDNzmhWp/gCyc1HVHGKShvhlncqI4lydFASjcFhMmhcM4AaEuHh I4+Z+sIOKqaETgGfr0vleunYGB6JzsdA/wqJ5eG8mk0iASolqTConlYEDfdjlYQBiFiO 0cXA== X-Gm-Message-State: AA+aEWYjISSkYfRJg/8IB64uWfyEl0x1IlCqptkON+OFYT2X+4vxJp4K 7636Z25Z38ni4OZyolVzQyF1Kc6j X-Google-Smtp-Source: AFSGD/VJUwz8hSsiCkCW72P16fPoMNPMYvOguRXVqnvk9p7hO9vwQz2SvboL5rWpQMxYOx5+QDSLYQ== X-Received: by 2002:a0c:8542:: with SMTP id n60mr385342qva.205.1544736199409; Thu, 13 Dec 2018 13:23:19 -0800 (PST) Received: from localhost.localdomain ([142.154.219.74]) by smtp.gmail.com with ESMTPSA id f13sm1552840qkm.52.2018.12.13.13.23.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Dec 2018 13:23:18 -0800 (PST) From: John Passaro To: git@vger.kernel.org Cc: gitster@pobox.com, alex.crezoff@gmail.com, peff@peff.net, mgorny@gentoo.org, John Passaro Subject: [PATCH 3/4] doc, tests: pretty behavior when gpg missing Date: Thu, 13 Dec 2018 16:22:55 -0500 Message-Id: <20181213212256.48122-4-john.a.passaro@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181213212256.48122-1-john.a.passaro@gmail.com> References: <20181213212256.48122-1-john.a.passaro@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Test that when GPG cannot be run, new placeholders %GR and %G+ are unaffected, %G? always returns 'N', and other GPG-related placeholders return blank. As of e5a329a279 ("run-command: report exec failure" 2018-12-11), if GPG cannot be run and placeholders requiring GPG are given, git complains to stderr that GPG cannot be found. That commit included low-level tests for this behavior. Now, test it also at the level of everyday user commands. Signed-off-by: John Passaro --- Documentation/pretty-formats.txt | 6 +- t/t7510-signed-commit.sh | 95 ++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 2 deletions(-) diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index 582454a4f7..4a83796250 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -144,7 +144,9 @@ ifndef::git-rev-list[] endif::git-rev-list[] - '%GR': contents of the commits signature (blank when unsigned) - '%G+': "Y" if the commit is signed, "N" otherwise -- '%GG': raw verification message from GPG for a signed commit +- '%GG': raw verification message from GPG for a signed commit. + This and all the other %G* placeholders, other than %GR, %G+, and + %G?, return blank if GPG cannot be run. - '%G?': show "G" for a good (valid) signature, "B" for a bad signature, "U" for a good signature with unknown validity, @@ -152,7 +154,7 @@ endif::git-rev-list[] "Y" for a good signature made by an expired key, "R" for a good signature made by a revoked key, "E" if the signature cannot be checked (e.g. missing key) - and "N" for no signature + and "N" for no signature (e.g. unsigned, or GPG cannot be run) - '%GS': show the name of the signer for a signed commit - '%GK': show the key used to sign a signed commit - '%GF': show the fingerprint of the key used to sign a signed commit diff --git a/t/t7510-signed-commit.sh b/t/t7510-signed-commit.sh index aff6b1eb3a..d65425eddc 100755 --- a/t/t7510-signed-commit.sh +++ b/t/t7510-signed-commit.sh @@ -170,6 +170,48 @@ test_expect_success GPG 'amending already signed commit' ' ! grep "BAD signature from" actual ' +test_expect_success GPG 'show custom format fields for signed commit if gpg is missing' ' + cat >expect <<-\EOF && + N + + + + + Y + EOF + test_config gpg.program this-is-not-a-program && + git log -n1 --format="%G?%n%GK%n%GS%n%GF%n%GP%n%G+" sixth-signed >actual 2>/dev/null && + test_cmp expect actual +' + +test_expect_success GPG 'show custom format fields for unsigned commit if gpg is missing' ' + cat >expect <<-\EOF && + N + + + + + N + EOF + test_config gpg.program this-is-not-a-program && + git log -n1 --format="%G?%n%GK%n%GS%n%GF%n%GP%n%G+" seventh-unsigned >actual 2>/dev/null && + test_cmp expect actual +' + +test_expect_success GPG 'show error for custom format fields on signed commit if gpg is missing' ' + test_config gpg.program this-is-not-a-program && + git log -n1 --format="%G?%n%GK%n%GS%n%GF%n%GP%n%G+" sixth-signed >/dev/null 2>errors && + test $(wc -l /dev/null 2>errors && + test_must_be_empty errors +' + test_expect_success GPG 'show good signature with custom format' ' cat >expect <<-\EOF && G @@ -240,6 +282,14 @@ test_expect_success GPG 'show lack of raw signature with custom format' ' test_must_be_empty actual ' +test_expect_success GPG 'show lack of raw signature with custom format without running GPG' ' + echo N > expected && + test_config gpg.program this-is-not-a-program && + git log -1 --format="%G+%GR" seventh-unsigned >actual 2>errors && + test_cmp expected actual && + test_must_be_empty errors +' + test_expect_success GPG 'show raw signature with custom format' ' git log -1 --format=format:"%GR" sixth-signed >output && cat output && @@ -250,6 +300,51 @@ test_expect_success GPG 'show raw signature with custom format' ' tail -n1 output | grep -q "^---*END PGP SIGNATURE---*$" ' +test_expect_success GPG 'show raw signature with custom format without running GPG' ' + test_config gpg.program this-is-not-a-program && + git log -1 --format=format:"%GR" sixth-signed >rawsig 2>errors && + cat rawsig && + head -n1 rawsig | grep -q "^---*BEGIN PGP SIGNATURE---*$" && + sed 1d rawsig | grep -q "^$" && + sed "1,/^$/d" rawsig | grep -q "^[a-zA-Z0-9+/][a-zA-Z0-9+/=]*$" && + tail -n2 rawsig | head -n1 | grep -q "^=[a-zA-Z0-9+/][a-zA-Z0-9+/=]*$" && + tail -n1 rawsig | grep -q "^---*END PGP SIGNATURE---*$" && + test_must_be_empty errors +' + +test_expect_success GPG 'show presence of gpgsig with custom format when gpg is missing without errors' ' + echo Y > expected && + git log -1 --format=%G+ sixth-signed >output 2>errors && + test_cmp expected output && + test_must_be_empty errors +' + +test_expect_success GPG 'show presence of invalid gpgsig header' ' + printf gpgsig >gpgsig-header && + tee prank-signature <<-\EOF | sed "s/^/ /" >>gpgsig-header && + this is not a signature but an awful... + 888 + 888 + 888 + 88888b. 888d888 8888b. 88888b. 888 888 + 888 "88b 888P" "88b 888 "88b 888 .88P + 888 888 888 .d888888 888 888 888888K + 888 d88P 888 888 888 888 888 888 "88b + 88888P" 888 "Y888888 888 888 888 888 + 888 + 888 + 888 + EOF + git cat-file commit seventh-unsigned >bare-commit-data && + sed "/^committer/r gpgsig-header" bare-commit-data >commit-data && + git hash-object -w -t commit commit-data >commit && + echo Y >expected && + cat prank-signature >>expected && + git log -n1 --format=format:%G+%n%GR $(cat commit) >actual 2>errors && + test_cmp expected actual && + test_must_be_empty errors +' + test_expect_success GPG 'log.showsignature behaves like --show-signature' ' test_config log.showsignature true && git show initial >actual && From patchwork Thu Dec 13 21:22:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro X-Patchwork-Id: 10729947 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CEE2E112E for ; Thu, 13 Dec 2018 21:23:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0F522C7E0 for ; Thu, 13 Dec 2018 21:23:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3DAE2CBCF; Thu, 13 Dec 2018 21:23:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C5A52C7E0 for ; Thu, 13 Dec 2018 21:23:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727160AbeLMVX0 (ORCPT ); Thu, 13 Dec 2018 16:23:26 -0500 Received: from mail-qt1-f193.google.com ([209.85.160.193]:45810 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726401AbeLMVX0 (ORCPT ); Thu, 13 Dec 2018 16:23:26 -0500 Received: by mail-qt1-f193.google.com with SMTP id e5so3879167qtr.12 for ; Thu, 13 Dec 2018 13:23:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fja8K5LmfMs13uRZ+FONl6J6+s955BVNqg9xzknmhSg=; b=tW2MEmc4SZ05EYZK/UzkppB+HyJaux8qmqNdE3HcJyCt4xfQ07dZqyrRVkvCn+RPd0 1whY7RCo52SmcvWwCulbuTi8DbGQFMLdOfWtp7HtajULJuHKHcscoZ5RQyfZRWC+YjET LR4cctSfyY/IL0qaYIggv6V3h5vkja3wWHXq/QMFM5SytFrBKew+TU/5oMpHtbj0QBpa BwVh2FxRR5Fvywk7FUZF6pwnNFPKCy8QCtsydPqQ+jL3XOFtvQPF8TvUntM3Vb+Sf/Gd e4H//GQ+YTZUQ2K6fo5x9WABHAxbzHv2q4qYbUlN2IwFd2Uc2RDPxhihCWd6yx3IAyKq gF9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fja8K5LmfMs13uRZ+FONl6J6+s955BVNqg9xzknmhSg=; b=mIDWHTxD85acsK9VSngifmfnMhrtGaVGgZmf0J4JxjyWy408Z441Jb6sT0izyHfjrV fglwRIBN6wypu2vJ5EyYxDk9bhaWltMErwSHX9CCET26SJ4UFFvrlIgXLZldjS3w0PY1 WDhH4sHnBxRZ3DLa+IDVCxMPHFz9RG6mAbHL3HszfEn+uPhmLd7mHEfhxtFzAMbiCTCZ KFgH5ix6BxPnR+V/KSWmm6UceBMqbnIIyiIRSOZFDoAkj20Mcedk1664Kf0nFnNY4eD3 K+Kowb9K8n/7l3BvdM2Ploqr4DpfXZtSTLQBjBgRqxAxpxhg0yzJZtDRZ5mEmAonhR6d WGSQ== X-Gm-Message-State: AA+aEWYNfYhKl1NB5TOGjEEgAcDAP63mP57gHlOlCxlCS6pxfxybDLLZ 8nZRbygTB8hE2TrNLsDv2bd0RacQ X-Google-Smtp-Source: AFSGD/XUargmSuIHcUjqGrCPkpiTB9p1JiNBibsUw/OyzzRvlQPY8BySpPSvHDlFSx/tk3PeAaVLGA== X-Received: by 2002:ac8:35eb:: with SMTP id l40mr408776qtb.165.1544736204567; Thu, 13 Dec 2018 13:23:24 -0800 (PST) Received: from localhost.localdomain ([142.154.219.74]) by smtp.gmail.com with ESMTPSA id f13sm1552840qkm.52.2018.12.13.13.23.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Dec 2018 13:23:23 -0800 (PST) From: John Passaro To: git@vger.kernel.org Cc: gitster@pobox.com, alex.crezoff@gmail.com, peff@peff.net, mgorny@gentoo.org, John Passaro Subject: [PATCH 4/4] docs/pretty-formats: add explanation + copy edits Date: Thu, 13 Dec 2018 16:22:56 -0500 Message-Id: <20181213212256.48122-5-john.a.passaro@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181213212256.48122-1-john.a.passaro@gmail.com> References: <20181213212256.48122-1-john.a.passaro@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Clarify description of %G? = "U" to say it can mean good signature but untrusted key. Make wording consistent between %G* placeholders and other placeholders by removing the verb "show". Signed-off-by: John Passaro --- Documentation/pretty-formats.txt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index 4a83796250..32c2f75060 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -147,18 +147,19 @@ endif::git-rev-list[] - '%GG': raw verification message from GPG for a signed commit. This and all the other %G* placeholders, other than %GR, %G+, and %G?, return blank if GPG cannot be run. -- '%G?': show "G" for a good (valid) signature, +- '%G?': "G" for a good (valid) signature, "B" for a bad signature, - "U" for a good signature with unknown validity, + "U" for a good signature with unknown validity (e.g. key is known but + not trusted), "X" for a good signature that has expired, "Y" for a good signature made by an expired key, "R" for a good signature made by a revoked key, "E" if the signature cannot be checked (e.g. missing key) and "N" for no signature (e.g. unsigned, or GPG cannot be run) -- '%GS': show the name of the signer for a signed commit -- '%GK': show the key used to sign a signed commit -- '%GF': show the fingerprint of the key used to sign a signed commit -- '%GP': show the fingerprint of the primary key whose subkey was used +- '%GS': name of the signer for a signed commit +- '%GK': key used to sign a signed commit +- '%GF': fingerprint of the key used to sign a signed commit +- '%GP': fingerprint of the primary key whose subkey was used to sign a signed commit - '%gD': reflog selector, e.g., `refs/stash@{1}` or `refs/stash@{2 minutes ago`}; the format follows the rules described