Skip to content

Commit

Permalink
rebase --keep-base: imply --no-fork-point
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
phillipwood committed Sep 5, 2022
1 parent 2cc3c82 commit 116cde9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Documentation/git-rebase.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ leave out at most one of A and B, in which case it defaults to HEAD.
merge base of `<upstream>` and `<branch>`. Running
`git rebase --keep-base <upstream> <branch>` is equivalent to
running
`git rebase --reapply-cherry-picks --onto <upstream>...<branch> <upstream> <branch>`.
`git rebase --reapply-cherry-picks --no-fork-point --onto <upstream>...<branch> <upstream> <branch>`.
+
This option is useful in the case where one is developing a feature on
top of an upstream branch. While the feature is being worked on, the
Expand Down Expand Up @@ -452,9 +452,9 @@ When `--fork-point` is active, 'fork_point' will be used instead of
<branch>` command (see linkgit:git-merge-base[1]). If 'fork_point'
ends up being empty, the `<upstream>` will be used as a fallback.
+
If `<upstream>` is given on the command line, then the default is
`--no-fork-point`, otherwise the default is `--fork-point`. See also
`rebase.forkpoint` in linkgit:git-config[1].
If `<upstream>` or `--keep-base` is given on the command line, then
the default is `--no-fork-point`, otherwise the default is
`--fork-point`. See also `rebase.forkpoint` in linkgit:git-config[1].
+
If your branch was based on `<upstream>` but `<upstream>` was rewound and
your branch contains commits which were dropped, this option can be used
Expand Down
6 changes: 6 additions & 0 deletions builtin/rebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
die(_("options '%s' and '%s' cannot be used together"), "--keep-base", "--onto");
if (options.root)
die(_("options '%s' and '%s' cannot be used together"), "--keep-base", "--root");
/*
* --keep-base defaults to --no-fork-point to keep the
* base the same.
*/
if (options.fork_point < 0)
options.fork_point = 0;
}
/*
* --keep-base defaults to --reapply-cherry-picks as it is confusing if
Expand Down
2 changes: 1 addition & 1 deletion t/t3431-rebase-fork-point.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test_rebase () {

test_rebase 'G F E D B A'
test_rebase 'G F D B A' --onto D
test_rebase 'G F B A' --keep-base
test_rebase 'G F C B A' --keep-base
test_rebase 'G F C E D B A' --no-fork-point
test_rebase 'G F C D B A' --no-fork-point --onto D
test_rebase 'G F C B A' --no-fork-point --keep-base
Expand Down

0 comments on commit 116cde9

Please sign in to comment.