rebase --keep-base: imply --no-fork-point

Given the name of the option it is confusing if --keep-base actually changes the base of the branch without --fork-point being explicitly given on the command line. The combination of --keep-base with an explicit --fork-point is still supported even though --fork-point means we do not keep the same base if the upstream branch has been rewound. We do this in case anyone is relying on this behavior which is tested in t3431[1] [1] https://lore.kernel.org/git/20200715032014.GA10818@generichostname/ Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Phillip Wood committed Oct 17, 2022 at 13:17 UTC aa1df8146d70bb85c63b0999868fe29aebc1173e
3 files changed +11 -5
Documentation/git-rebase.txt
+4 -4
@@ -218,7 +218,7 @@ leave out at most one of A and B, in which case it defaults to HEAD.
218 merge base of `<upstream>` and `<branch>`. Running
219 `git rebase --keep-base <upstream> <branch>` is equivalent to
220 running
221 - `git rebase --reapply-cherry-picks --onto <upstream>...<branch> <upstream> <branch>`.
221 + `git rebase --reapply-cherry-picks --no-fork-point --onto <upstream>...<branch> <upstream> <branch>`.
222 +
223 This option is useful in the case where one is developing a feature on
224 top of an upstream branch. While the feature is being worked on, the
@@ -452,9 +452,9 @@ When `--fork-point` is active, 'fork_point' will be used instead of
452 <branch>` command (see linkgit:git-merge-base[1]). If 'fork_point'
453 ends up being empty, the `<upstream>` will be used as a fallback.
454 +
455 -If `<upstream>` is given on the command line, then the default is
456 -`--no-fork-point`, otherwise the default is `--fork-point`. See also
457 -`rebase.forkpoint` in linkgit:git-config[1].
455 +If `<upstream>` or `--keep-base` is given on the command line, then
456 +the default is `--no-fork-point`, otherwise the default is
457 +`--fork-point`. See also `rebase.forkpoint` in linkgit:git-config[1].
458 +
459 If your branch was based on `<upstream>` but `<upstream>` was rewound and
460 your branch contains commits which were dropped, this option can be used
builtin/rebase.c
+6
@@ -1230,6 +1230,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1230 die(_("options '%s' and '%s' cannot be used together"), "--keep-base", "--onto");
1231 if (options.root)
1232 die(_("options '%s' and '%s' cannot be used together"), "--keep-base", "--root");
1233 + /*
1234 + * --keep-base defaults to --no-fork-point to keep the
1235 + * base the same.
1236 + */
1237 + if (options.fork_point < 0)
1238 + options.fork_point = 0;
1239 }
1240 /*
1241 * --keep-base defaults to --reapply-cherry-picks to avoid losing
t/t3431-rebase-fork-point.sh
+1 -1
@@ -50,7 +50,7 @@ test_rebase () {
50
51 test_rebase 'G F E D B A'
52 test_rebase 'G F D B A' --onto D
53 -test_rebase 'G F B A' --keep-base
53 +test_rebase 'G F C B A' --keep-base
54 test_rebase 'G F C E D B A' --no-fork-point
55 test_rebase 'G F C D B A' --no-fork-point --onto D
56 test_rebase 'G F C B A' --no-fork-point --keep-base