Skip to content

Commit df478b7

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

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

Documentation/git-cherry-pick.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ effect to your index in a row.
103103
cherry-pick'ed commit, then a fast forward to this commit will
104104
be performed.
105105

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+
106115
--strategy=<strategy>::
107116
Use the given merge strategy. Should only be used once.
108117
See the MERGE STRATEGIES section in linkgit:git-merge[1]

builtin/revert.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,14 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
114114
OPT_END(),
115115
OPT_END(),
116116
OPT_END(),
117+
OPT_END(),
117118
};
118119

119120
if (opts->action == REPLAY_PICK) {
120121
struct option cp_extra[] = {
121122
OPT_BOOLEAN('x', NULL, &opts->record_origin, "append commit name"),
122123
OPT_BOOLEAN(0, "ff", &opts->allow_ff, "allow fast-forward"),
124+
OPT_BOOLEAN(0, "allow-empty", &opts->allow_empty, "preserve empty commits"),
123125
OPT_END(),
124126
};
125127
if (parse_options_concat(options, ARRAY_SIZE(options), cp_extra))

sequencer.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
260260
*/
261261
static int run_git_commit(const char *defmsg, struct replay_opts *opts)
262262
{
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];
265265
int i = 0;
266266

267267
args[i++] = "commit";
@@ -272,6 +272,9 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts)
272272
args[i++] = "-F";
273273
args[i++] = defmsg;
274274
}
275+
if (opts->allow_empty)
276+
args[i++] = "--allow-empty";
277+
275278
args[i] = NULL;
276279

277280
return run_command_v_opt(args, RUN_GIT_CMD);

sequencer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct replay_opts {
2929
int signoff;
3030
int allow_ff;
3131
int allow_rerere_auto;
32+
int allow_empty;
3233

3334
int mainline;
3435

0 commit comments

Comments
 (0)