summaryrefslogtreecommitdiff
path: root/builtin/rebase.c
diff options
context:
space:
mode:
authorPhillip Wood <phillip.wood@dunelm.org.uk>2022-10-17 13:17:44 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-10-17 18:53:03 (GMT)
commitce5238a690821d1de230091dd6c9c13a99ed6752 (patch)
tree41fd3107108a93cd90c4a5d82f8bef65df5c7930 /builtin/rebase.c
parentd42c9ffa0fa169ea51c971d1143b3f20d5a32d83 (diff)
downloadgit-ce5238a690821d1de230091dd6c9c13a99ed6752.zip
git-ce5238a690821d1de230091dd6c9c13a99ed6752.tar.gz
git-ce5238a690821d1de230091dd6c9c13a99ed6752.tar.bz2
rebase --keep-base: imply --reapply-cherry-picks
As --keep-base does not rebase the branch it is confusing if it removes commits that have been cherry-picked to the upstream branch. As --reapply-cherry-picks is not supported by the "apply" backend this commit ensures that cherry-picks are reapplied by forcing the upstream commit to match the onto commit unless --no-reapply-cherry-picks is given. Reported-by: Philippe Blain <levraiphilippeblain@gmail.com> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/rebase.c')
-rw-r--r--builtin/rebase.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/builtin/rebase.c b/builtin/rebase.c
index 9ee3ab6..0287f3e 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -1171,6 +1171,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0;
+ options.reapply_cherry_picks = -1;
options.allow_empty_message = 1;
git_config(rebase_config, &options);
/* options.gpg_sign_opt will be either "-S" or NULL */
@@ -1230,6 +1231,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
if (options.root)
die(_("options '%s' and '%s' cannot be used together"), "--keep-base", "--root");
}
+ /*
+ * --keep-base defaults to --reapply-cherry-picks to avoid losing
+ * commits when using this option.
+ */
+ if (options.reapply_cherry_picks < 0)
+ options.reapply_cherry_picks = keep_base;
if (options.root && options.fork_point > 0)
die(_("options '%s' and '%s' cannot be used together"), "--root", "--fork-point");
@@ -1406,7 +1413,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
if (options.empty != EMPTY_UNSPECIFIED)
imply_merge(&options, "--empty");
- if (options.reapply_cherry_picks)
+ /*
+ * --keep-base implements --reapply-cherry-picks by altering upstream so
+ * it works with both backends.
+ */
+ if (options.reapply_cherry_picks && !keep_base)
imply_merge(&options, "--reapply-cherry-picks");
if (gpg_sign)
@@ -1672,6 +1683,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
fill_branch_base(&options, &branch_base);
}
+ if (keep_base && options.reapply_cherry_picks)
+ options.upstream = options.onto;
+
if (options.fork_point > 0)
options.restrict_revision =
get_fork_point(options.upstream_name, options.orig_head);