Skip to content

Commit

Permalink
git-cherry-pick: add allow-empty option
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Neil Horman authored and Junio C Hamano committed Apr 11, 2012
1 parent e8dde3e commit df478b7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Documentation/git-cherry-pick.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ effect to your index in a row.
cherry-pick'ed commit, then a fast forward to this commit will
be performed.

--allow-empty::
By default, cherry-picking an empty commit will fail,
indicating that an explicit invocation of `git commit
--allow-empty` is required. This option overrides that
behavior, allowing empty commits to be preserved automatically
in a cherry-pick. Note that when "--ff" is in effect, empty
commits that meet the "fast-forward" requirement will be kept
even without this option.

--strategy=<strategy>::
Use the given merge strategy. Should only be used once.
See the MERGE STRATEGIES section in linkgit:git-merge[1]
Expand Down
2 changes: 2 additions & 0 deletions builtin/revert.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,14 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
OPT_END(),
OPT_END(),
OPT_END(),
OPT_END(),
};

if (opts->action == REPLAY_PICK) {
struct option cp_extra[] = {
OPT_BOOLEAN('x', NULL, &opts->record_origin, "append commit name"),
OPT_BOOLEAN(0, "ff", &opts->allow_ff, "allow fast-forward"),
OPT_BOOLEAN(0, "allow-empty", &opts->allow_empty, "preserve empty commits"),
OPT_END(),
};
if (parse_options_concat(options, ARRAY_SIZE(options), cp_extra))
Expand Down
7 changes: 5 additions & 2 deletions sequencer.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
*/
static int run_git_commit(const char *defmsg, struct replay_opts *opts)
{
/* 6 is max possible length of our args array including NULL */
const char *args[6];
/* 7 is max possible length of our args array including NULL */
const char *args[7];
int i = 0;

args[i++] = "commit";
Expand All @@ -272,6 +272,9 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts)
args[i++] = "-F";
args[i++] = defmsg;
}
if (opts->allow_empty)
args[i++] = "--allow-empty";

args[i] = NULL;

return run_command_v_opt(args, RUN_GIT_CMD);
Expand Down
1 change: 1 addition & 0 deletions sequencer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct replay_opts {
int signoff;
int allow_ff;
int allow_rerere_auto;
int allow_empty;

int mainline;

Expand Down

0 comments on commit df478b7

Please sign in to comment.