Skip to content

Commit b36c590

Browse files
phillipwoodgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b34eeea commit b36c590

File tree

4 files changed

+60
-3
lines changed

4 files changed

+60
-3
lines changed

builtin/rebase--helper.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ static const char * const builtin_rebase_helper_usage[] = {
99
NULL
1010
};
1111

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+
1223
int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
1324
{
1425
struct replay_opts opts = REPLAY_OPTS_INIT;
@@ -39,7 +50,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
3950
OPT_END()
4051
};
4152

42-
git_config(git_default_config, NULL);
53+
git_config(git_rebase_helper_config, NULL);
4354

4455
opts.action = REPLAY_INTERACTIVE_REBASE;
4556
opts.allow_ff = 1;

builtin/revert.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ static const char * const cherry_pick_usage[] = {
3131
NULL
3232
};
3333

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+
3445
static const char *action_name(const struct replay_opts *opts)
3546
{
3647
return opts->action == REPLAY_REVERT ? "revert" : "cherry-pick";
@@ -208,7 +219,7 @@ int cmd_revert(int argc, const char **argv, const char *prefix)
208219
if (isatty(0))
209220
opts.edit = 1;
210221
opts.action = REPLAY_REVERT;
211-
git_config(git_default_config, NULL);
222+
git_config(common_config, NULL);
212223
res = run_sequencer(argc, argv, &opts);
213224
if (res < 0)
214225
die(_("revert failed"));
@@ -221,7 +232,7 @@ int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
221232
int res;
222233

223234
opts.action = REPLAY_PICK;
224-
git_config(git_default_config, NULL);
235+
git_config(common_config, NULL);
225236
res = run_sequencer(argc, argv, &opts);
226237
if (res < 0)
227238
die(_("cherry-pick failed"));

sequencer.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,40 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts,
688688
return run_command(&cmd);
689689
}
690690

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+
691725
static int rest_is_empty(const struct strbuf *sb, int start)
692726
{
693727
int i, eol;

sequencer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ extern const char sign_off_header[];
5757

5858
void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag);
5959
void append_conflicts_hint(struct strbuf *msgbuf);
60+
int git_sequencer_config(const char *k, const char *v, void *cb);
6061

6162
enum commit_msg_cleanup_mode {
6263
COMMIT_MSG_CLEANUP_SPACE,

0 commit comments

Comments
 (0)