Skip to content

Commit 5de89d3

Browse files
committed
Merge branch 'jc/show-sig'
* jc/show-sig: log --show-signature: reword the common two-head merge case log-tree: show mergetag in log --show-signature output log-tree.c: small refactor in show_signature() commit --amend -S: strip existing gpgsig headers verify_signed_buffer: fix stale comment gpg-interface: allow use of a custom GPG binary pretty: %G[?GS] placeholders test "commit -S" and "log --show-signature" log: --show-signature commit: teach --gpg-sign option Conflicts: builtin/commit-tree.c builtin/commit.c builtin/merge.c notes-cache.c pretty.c
2 parents 4a3a1ed + d041ffa commit 5de89d3

File tree

16 files changed

+488
-34
lines changed

16 files changed

+488
-34
lines changed

Documentation/RelNotes/1.7.9.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ Unless otherwise noted, all the fixes since v1.7.8 in the maintenance
9999
releases are contained in this release (see release notes to them for
100100
details).
101101

102-
* gitweb did not correctly fall back to configured $fallback_encoding
103-
that is not 'latin1'.
104-
(merge b13e3ea jn/maint-gitweb-utf8-fix later to maint).
105-
106102
--
107103
exec >/var/tmp/1
108104
O=v1.7.8.2-301-g48de656

Documentation/config.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,17 @@ grep.lineNumber::
11231123
grep.extendedRegexp::
11241124
If set to true, enable '--extended-regexp' option by default.
11251125

1126+
gpg.program::
1127+
Use this custom program instead of "gpg" found on $PATH when
1128+
making or verifying a PGP signature. The program must support the
1129+
same command line interface as GPG, namely, to verify a detached
1130+
signature, "gpg --verify $file - <$signature" is run, and the
1131+
program is expected to signal a good signature by exiting with
1132+
code 0, and to generate an ascii-armored detached signature, the
1133+
standard input of "gpg -bsau $key" is fed with the contents to be
1134+
signed, and the program is expected to send the result to its
1135+
standard output.
1136+
11261137
gui.commitmsgwidth::
11271138
Defines how wide the commit message window is in the
11281139
linkgit:git-gui[1]. "75" is the default.

Documentation/git-tag.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ created (i.e. a lightweight tag).
3838
A GnuPG signed tag object will be created when `-s` or `-u
3939
<key-id>` is used. When `-u <key-id>` is not used, the
4040
committer identity for the current user is used to find the
41-
GnuPG key for signing.
41+
GnuPG key for signing. The configuration variable `gpg.program`
42+
is used to specify custom GnuPG binary.
43+
4244

4345
OPTIONS
4446
-------
@@ -48,11 +50,11 @@ OPTIONS
4850

4951
-s::
5052
--sign::
51-
Make a GPG-signed tag, using the default e-mail address's key
53+
Make a GPG-signed tag, using the default e-mail address's key.
5254

5355
-u <key-id>::
5456
--local-user=<key-id>::
55-
Make a GPG-signed tag, using the given key
57+
Make a GPG-signed tag, using the given key.
5658

5759
-f::
5860
--force::

builtin/commit-tree.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
#include "tree.h"
99
#include "builtin.h"
1010
#include "utf8.h"
11+
#include "gpg-interface.h"
1112

12-
static const char commit_tree_usage[] = "git commit-tree [(-p <sha1>)...] [-m <message>] [-F <file>] <sha1> <changelog";
13+
static const char commit_tree_usage[] = "git commit-tree [(-p <sha1>)...] [-S<signer>] [-m <message>] [-F <file>] <sha1> <changelog";
1314

1415
static void new_parent(struct commit *parent, struct commit_list **parents_p)
1516
{
@@ -25,19 +26,31 @@ static void new_parent(struct commit *parent, struct commit_list **parents_p)
2526
commit_list_insert(parent, parents_p);
2627
}
2728

29+
static int commit_tree_config(const char *var, const char *value, void *cb)
30+
{
31+
int status = git_gpg_config(var, value, NULL);
32+
if (status)
33+
return status;
34+
return git_default_config(var, value, cb);
35+
}
36+
2837
int cmd_commit_tree(int argc, const char **argv, const char *prefix)
2938
{
3039
int i, got_tree = 0;
3140
struct commit_list *parents = NULL;
3241
unsigned char tree_sha1[20];
3342
unsigned char commit_sha1[20];
3443
struct strbuf buffer = STRBUF_INIT;
44+
const char *sign_commit = NULL;
3545

36-
git_config(git_default_config, NULL);
46+
git_config(commit_tree_config, NULL);
3747

3848
if (argc < 2 || !strcmp(argv[1], "-h"))
3949
usage(commit_tree_usage);
4050

51+
if (get_sha1(argv[1], tree_sha1))
52+
die("Not a valid object name %s", argv[1]);
53+
4154
for (i = 1; i < argc; i++) {
4255
const char *arg = argv[i];
4356
if (!strcmp(arg, "-p")) {
@@ -51,6 +64,11 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
5164
continue;
5265
}
5366

67+
if (!memcmp(arg, "-S", 2)) {
68+
sign_commit = arg + 2;
69+
continue;
70+
}
71+
5472
if (!strcmp(arg, "-m")) {
5573
if (argc <= ++i)
5674
usage(commit_tree_usage);
@@ -98,7 +116,8 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
98116
die_errno("git commit-tree: failed to read");
99117
}
100118

101-
if (commit_tree(&buffer, tree_sha1, parents, commit_sha1, NULL)) {
119+
if (commit_tree(&buffer, tree_sha1, parents, commit_sha1,
120+
NULL, sign_commit)) {
102121
strbuf_release(&buffer);
103122
return 1;
104123
}

builtin/commit.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "unpack-trees.h"
2727
#include "quote.h"
2828
#include "submodule.h"
29+
#include "gpg-interface.h"
2930

3031
static const char * const builtin_commit_usage[] = {
3132
"git commit [options] [--] <filepattern>...",
@@ -86,6 +87,8 @@ static int edit_flag = -1; /* unspecified */
8687
static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
8788
static int no_post_rewrite, allow_empty_message;
8889
static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
90+
static char *sign_commit;
91+
8992
/*
9093
* The default commit message cleanup mode will remove the lines
9194
* beginning with # (shell comments) and leading and trailing
@@ -145,6 +148,8 @@ static struct option builtin_commit_options[] = {
145148
OPT_BOOL('e', "edit", &edit_flag, "force edit of commit"),
146149
OPT_STRING(0, "cleanup", &cleanup_arg, "default", "how to strip spaces and #comments from message"),
147150
OPT_BOOLEAN(0, "status", &include_status, "include status in commit message template"),
151+
{ OPTION_STRING, 'S', "gpg-sign", &sign_commit, "key id",
152+
"GPG sign commit", PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
148153
/* end commit message options */
149154

150155
OPT_GROUP("Commit contents options"),
@@ -1325,6 +1330,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
13251330
static int git_commit_config(const char *k, const char *v, void *cb)
13261331
{
13271332
struct wt_status *s = cb;
1333+
int status;
13281334

13291335
if (!strcmp(k, "commit.template"))
13301336
return git_config_pathname(&template_file, k, v);
@@ -1333,6 +1339,9 @@ static int git_commit_config(const char *k, const char *v, void *cb)
13331339
return 0;
13341340
}
13351341

1342+
status = git_gpg_config(k, v, NULL);
1343+
if (status)
1344+
return status;
13361345
return git_status_config(k, v, s);
13371346
}
13381347

@@ -1486,14 +1495,15 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
14861495
}
14871496

14881497
if (amend) {
1489-
extra = read_commit_extra_headers(current_head);
1498+
const char *exclude_gpgsig[2] = { "gpgsig", NULL };
1499+
extra = read_commit_extra_headers(current_head, exclude_gpgsig);
14901500
} else {
14911501
struct commit_extra_header **tail = &extra;
14921502
append_merge_tag_headers(parents, &tail);
14931503
}
14941504

14951505
if (commit_tree_extended(&sb, active_cache_tree->sha1, parents, sha1,
1496-
author_ident.buf, extra)) {
1506+
author_ident.buf, sign_commit, extra)) {
14971507
rollback_index_files();
14981508
die(_("failed to write commit object"));
14991509
}

builtin/merge.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "resolve-undo.h"
2828
#include "remote.h"
2929
#include "fmt-merge-msg.h"
30+
#include "gpg-interface.h"
3031

3132
#define DEFAULT_TWOHEAD (1<<0)
3233
#define DEFAULT_OCTOPUS (1<<1)
@@ -64,6 +65,7 @@ static int allow_rerere_auto;
6465
static int abort_current_merge;
6566
static int show_progress = -1;
6667
static int default_to_upstream;
68+
static const char *sign_commit;
6769

6870
static struct strategy all_strategy[] = {
6971
{ "recursive", DEFAULT_TWOHEAD | NO_TRIVIAL },
@@ -209,6 +211,8 @@ static struct option builtin_merge_options[] = {
209211
OPT_BOOLEAN(0, "abort", &abort_current_merge,
210212
"abort the current in-progress merge"),
211213
OPT_SET_INT(0, "progress", &show_progress, "force progress reporting", 1),
214+
{ OPTION_STRING, 'S', "gpg-sign", &sign_commit, "key id",
215+
"GPG sign commit", PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
212216
OPT_BOOLEAN(0, "overwrite-ignore", &overwrite_ignore, "update ignored files (default)"),
213217
OPT_END()
214218
};
@@ -571,7 +575,11 @@ static int git_merge_config(const char *k, const char *v, void *cb)
571575
default_to_upstream = git_config_bool(k, v);
572576
return 0;
573577
}
578+
574579
status = fmt_merge_msg_config(k, v, cb);
580+
if (status)
581+
return status;
582+
status = git_gpg_config(k, v, NULL);
575583
if (status)
576584
return status;
577585
return git_diff_ui_config(k, v, cb);
@@ -910,7 +918,8 @@ static int merge_trivial(struct commit *head)
910918
parent->next->item = remoteheads->item;
911919
parent->next->next = NULL;
912920
prepare_to_commit();
913-
if (commit_tree(&merge_msg, result_tree, parent, result_commit, NULL))
921+
if (commit_tree(&merge_msg, result_tree, parent, result_commit, NULL,
922+
sign_commit))
914923
die(_("failed to write commit object"));
915924
finish(head, result_commit, "In-index merge");
916925
drop_save();
@@ -942,7 +951,8 @@ static int finish_automerge(struct commit *head,
942951
strbuf_addch(&merge_msg, '\n');
943952
prepare_to_commit();
944953
free_commit_list(remoteheads);
945-
if (commit_tree(&merge_msg, result_tree, parents, result_commit, NULL))
954+
if (commit_tree(&merge_msg, result_tree, parents, result_commit,
955+
NULL, sign_commit))
946956
die(_("failed to write commit object"));
947957
strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy);
948958
finish(head, result_commit, buf.buf);

0 commit comments

Comments
 (0)