git-cherry-pick: add allow-empty option
git cherry-pick fails when picking a non-ff commit that is empty. The advice given with the failure is that a git-commit --allow-empty should be issued to explicitly add the empty commit during the cherry pick. This option allows a user to specify before hand that they want to keep the empty commit. This eliminates the need to issue both a cherry pick and a commit operation. Signed-off-by: Neil Horman <nhorman@tuxdriver.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Neil Horman committed
Apr 11, 2012 at 16:21 UTC
df478b744cee9821eb2abbe2202d262b87a34289
4 files changed
+17
-2
Documentation/git-cherry-pick.txt
+9
@@ -103,6 +103,15 @@ effect to your index in a row.
103
cherry-pick'ed commit, then a fast forward to this commit will
104
be performed.
105
106
+--allow-empty::
107
+ By default, cherry-picking an empty commit will fail,
108
+ indicating that an explicit invocation of `git commit
109
+ --allow-empty` is required. This option overrides that
110
+ behavior, allowing empty commits to be preserved automatically
111
+ in a cherry-pick. Note that when "--ff" is in effect, empty
112
+ commits that meet the "fast-forward" requirement will be kept
113
+ even without this option.
114
+
115
--strategy=<strategy>::
116
Use the given merge strategy. Should only be used once.
117
See the MERGE STRATEGIES section in linkgit:git-merge[1]
builtin/revert.c
+2
@@ -114,12 +114,14 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
114
OPT_END(),
115
OPT_END(),
116
OPT_END(),
117
+ OPT_END(),
118
};
119
120
if (opts->action == REPLAY_PICK) {
121
struct option cp_extra[] = {
122
OPT_BOOLEAN('x', NULL, &opts->record_origin, "append commit name"),
123
OPT_BOOLEAN(0, "ff", &opts->allow_ff, "allow fast-forward"),
124
+ OPT_BOOLEAN(0, "allow-empty", &opts->allow_empty, "preserve empty commits"),
125
OPT_END(),
126
};
127
if (parse_options_concat(options, ARRAY_SIZE(options), cp_extra))
sequencer.c
+5
-2
@@ -260,8 +260,8 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
260
*/
261
static int run_git_commit(const char *defmsg, struct replay_opts *opts)
262
{
263
- /* 6 is max possible length of our args array including NULL */
264
- const char *args[6];
263
+ /* 7 is max possible length of our args array including NULL */
264
+ const char *args[7];
265
int i = 0;
266
267
args[i++] = "commit";
@@ -272,6 +272,9 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts)
272
args[i++] = "-F";
273
args[i++] = defmsg;
274
}
275
+ if (opts->allow_empty)
276
+ args[i++] = "--allow-empty";
277
+
278
args[i] = NULL;
279
280
return run_command_v_opt(args, RUN_GIT_CMD);
sequencer.h
+1
@@ -29,6 +29,7 @@ struct replay_opts {
29
int signoff;
30
int allow_ff;
31
int allow_rerere_auto;
32
+ int allow_empty;
33
34
int mainline;
35