sequencer: load commit related config
Load default values for message cleanup and gpg signing of commits in preparation for committing without forking 'git commit'. Note that we interpret commit.cleanup=scissors to mean COMMIT_MSG_CLEANUP_SPACE to be consistent with 'git commit' Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Phillip Wood committed
Nov 24, 2017 at 11:07 UTC
b36c5908135889bd9c48a8d44d4e07f59bf799ef
4 files changed
+60
-3
builtin/rebase--helper.c
+12
-1
@@ -9,6 +9,17 @@ static const char * const builtin_rebase_helper_usage[] = {
9
NULL
10
};
11
12
+static int git_rebase_helper_config(const char *k, const char *v, void *cb)
13
+{
14
+ int status;
15
+
16
+ status = git_sequencer_config(k, v, NULL);
17
+ if (status)
18
+ return status;
19
+
20
+ return git_default_config(k, v, NULL);
21
+}
22
+
23
int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
24
{
25
struct replay_opts opts = REPLAY_OPTS_INIT;
@@ -39,7 +50,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
50
OPT_END()
51
};
52
42
- git_config(git_default_config, NULL);
53
+ git_config(git_rebase_helper_config, NULL);
54
55
opts.action = REPLAY_INTERACTIVE_REBASE;
56
opts.allow_ff = 1;
builtin/revert.c
+13
-2
@@ -31,6 +31,17 @@ static const char * const cherry_pick_usage[] = {
31
NULL
32
};
33
34
+static int common_config(const char *k, const char *v, void *cb)
35
+{
36
+ int status;
37
+
38
+ status = git_sequencer_config(k, v, NULL);
39
+ if (status)
40
+ return status;
41
+
42
+ return git_default_config(k, v, NULL);
43
+}
44
+
45
static const char *action_name(const struct replay_opts *opts)
46
{
47
return opts->action == REPLAY_REVERT ? "revert" : "cherry-pick";
@@ -208,7 +219,7 @@ int cmd_revert(int argc, const char **argv, const char *prefix)
219
if (isatty(0))
220
opts.edit = 1;
221
opts.action = REPLAY_REVERT;
211
- git_config(git_default_config, NULL);
222
+ git_config(common_config, NULL);
223
res = run_sequencer(argc, argv, &opts);
224
if (res < 0)
225
die(_("revert failed"));
@@ -221,7 +232,7 @@ int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
232
int res;
233
234
opts.action = REPLAY_PICK;
224
- git_config(git_default_config, NULL);
235
+ git_config(common_config, NULL);
236
res = run_sequencer(argc, argv, &opts);
237
if (res < 0)
238
die(_("cherry-pick failed"));
sequencer.c
+34
@@ -688,6 +688,40 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts,
688
return run_command(&cmd);
689
}
690
691
+static enum commit_msg_cleanup_mode default_msg_cleanup =
692
+ COMMIT_MSG_CLEANUP_NONE;
693
+static char *default_gpg_sign;
694
+
695
+int git_sequencer_config(const char *k, const char *v, void *cb)
696
+{
697
+ if (!strcmp(k, "commit.cleanup")) {
698
+ int status;
699
+ const char *s;
700
+
701
+ status = git_config_string(&s, k, v);
702
+ if (status)
703
+ return status;
704
+
705
+ if (!strcmp(s, "verbatim"))
706
+ default_msg_cleanup = COMMIT_MSG_CLEANUP_NONE;
707
+ else if (!strcmp(s, "whitespace"))
708
+ default_msg_cleanup = COMMIT_MSG_CLEANUP_SPACE;
709
+ else if (!strcmp(s, "strip"))
710
+ default_msg_cleanup = COMMIT_MSG_CLEANUP_ALL;
711
+ else if (!strcmp(s, "scissors"))
712
+ default_msg_cleanup = COMMIT_MSG_CLEANUP_SPACE;
713
+
714
+ return status;
715
+ }
716
+
717
+ if (!strcmp(k, "commit.gpgsign")) {
718
+ default_gpg_sign = git_config_bool(k, v) ? "" : NULL;
719
+ return 0;
720
+ }
721
+
722
+ return git_gpg_config(k, v, NULL);
723
+}
724
+
725
static int rest_is_empty(const struct strbuf *sb, int start)
726
{
727
int i, eol;
sequencer.h
+1
@@ -57,6 +57,7 @@ extern const char sign_off_header[];
57
58
void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag);
59
void append_conflicts_hint(struct strbuf *msgbuf);
60
+int git_sequencer_config(const char *k, const char *v, void *cb);
61
62
enum commit_msg_cleanup_mode {
63
COMMIT_MSG_CLEANUP_SPACE,