cherry-pick: add --allow-empty-message option
Scripts such as "git rebase -i" cannot currently cherry-pick commits which have an empty commit message, as git cherry-pick calls git commit without the --allow-empty-message option. Add an --allow-empty-message option to git cherry-pick which is passed through to git commit, so this behaviour can be overridden. Signed-off-by: Chris Webb <chris@arachsys.com> Reviewed-by: Neil Horman <nhorman@tuxdriver.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Chris Webb committed
Aug 2, 2012 at 11:38 UTC
4bee958479bed1d3a8f20a75f33422ee49939dbf
5 files changed
+16
Documentation/git-cherry-pick.txt
+5
@@ -116,6 +116,11 @@ effect to your index in a row.
116
previous commit are dropped. To force the inclusion of those commits
117
use `--keep-redundant-commits`.
118
119
+--allow-empty-message::
120
+ By default, cherry-picking a commit with an empty message will fail.
121
+ This option overrides that behaviour, allowing commits with empty
122
+ messages to be cherry picked.
123
+
124
--keep-redundant-commits::
125
If a commit being cherry picked duplicates a commit already in the
126
current history, it will become empty. By default these
builtin/revert.c
+2
@@ -117,6 +117,7 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
117
OPT_END(),
118
OPT_END(),
119
OPT_END(),
120
+ OPT_END(),
121
};
122
123
if (opts->action == REPLAY_PICK) {
@@ -124,6 +125,7 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
125
OPT_BOOLEAN('x', NULL, &opts->record_origin, "append commit name"),
126
OPT_BOOLEAN(0, "ff", &opts->allow_ff, "allow fast-forward"),
127
OPT_BOOLEAN(0, "allow-empty", &opts->allow_empty, "preserve initially empty commits"),
128
+ OPT_BOOLEAN(0, "allow-empty-message", &opts->allow_empty_message, "allow commits with empty messages"),
129
OPT_BOOLEAN(0, "keep-redundant-commits", &opts->keep_redundant_commits, "keep redundant, empty commits"),
130
OPT_END(),
131
};
sequencer.c
+3
@@ -311,6 +311,9 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts,
311
if (allow_empty)
312
argv_array_push(&array, "--allow-empty");
313
314
+ if (opts->allow_empty_message)
315
+ argv_array_push(&array, "--allow-empty-message");
316
+
317
rc = run_command_v_opt(array.argv, RUN_GIT_CMD);
318
argv_array_clear(&array);
319
return rc;
sequencer.h
+1
@@ -30,6 +30,7 @@ struct replay_opts {
30
int allow_ff;
31
int allow_rerere_auto;
32
int allow_empty;
33
+ int allow_empty_message;
34
int keep_redundant_commits;
35
36
int mainline;
t/t3505-cherry-pick-empty.sh
+5
@@ -53,6 +53,11 @@ test_expect_success 'index lockfile was removed' '
53
54
'
55
56
+test_expect_success 'cherry-pick a commit with an empty message with --allow-empty-message' '
57
+ git checkout -f master &&
58
+ git cherry-pick --allow-empty-message empty-branch
59
+'
60
+
61
test_expect_success 'cherry pick an empty non-ff commit without --allow-empty' '
62
git checkout master &&
63
echo fourth >>file2 &&