rebase: add documentation and test for --no-rebase-merges

As far as I can tell, --no-rebase-merges has always worked, but has never been documented. It is especially important to document it before a rebase.rebaseMerges option is introduced so that users know how to override the config option on the command line. It's also important to clarify that --rebase-merges without an argument is not the same as --no-rebase-merges and not passing --rebase-merges is not the same as passing --rebase-merges=no-rebase-cousins. A test case is necessary to make sure that --no-rebase-merges keeps working after its code is refactored in the following patches of this series. The test case is a little contrived: It's unlikely that a user would type both --rebase-merges and --no-rebase-merges at the same time. However, if an alias is defined which includes --rebase-merges, the user might decide to add --no-rebase-merges to countermand that part of the alias but leave alone other flags set by the alias. Signed-off-by: Alex Henrie <alexhenrie24@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Alex Henrie committed Mar 25, 2023 at 21:06 UTC 7e5dcec3ca4dee6d8aedd64f4dba037949f36a67
2 files changed +21 -7
Documentation/git-rebase.txt
+11 -7
@@ -529,20 +529,24 @@ See also INCOMPATIBLE OPTIONS below.
529
530 -r::
531 --rebase-merges[=(rebase-cousins|no-rebase-cousins)]::
532 +--no-rebase-merges::
533 By default, a rebase will simply drop merge commits from the todo
534 list, and put the rebased commits into a single, linear branch.
535 With `--rebase-merges`, the rebase will instead try to preserve
536 the branching structure within the commits that are to be rebased,
537 by recreating the merge commits. Any resolved merge conflicts or
538 manual amendments in these merge commits will have to be
538 - resolved/re-applied manually.
539 + resolved/re-applied manually. `--no-rebase-merges` can be used to
540 + countermand a previous `--rebase-merges`.
541 +
540 -By default, or when `no-rebase-cousins` was specified, commits which do not
541 -have `<upstream>` as direct ancestor will keep their original branch point,
542 -i.e. commits that would be excluded by linkgit:git-log[1]'s
543 -`--ancestry-path` option will keep their original ancestry by default. If
544 -the `rebase-cousins` mode is turned on, such commits are instead rebased
545 -onto `<upstream>` (or `<onto>`, if specified).
542 +When rebasing merges, there are two modes: `rebase-cousins` and
543 +`no-rebase-cousins`. If the mode is not specified, it defaults to
544 +`no-rebase-cousins`. In `no-rebase-cousins` mode, commits which do not have
545 +`<upstream>` as direct ancestor will keep their original branch point, i.e.
546 +commits that would be excluded by linkgit:git-log[1]'s `--ancestry-path`
547 +option will keep their original ancestry by default. In `rebase-cousins` mode,
548 +such commits are instead rebased onto `<upstream>` (or `<onto>`, if
549 +specified).
550 +
551 It is currently only possible to recreate the merge commits using the
552 `ort` merge strategy; different merge strategies can be used only via
t/t3430-rebase-merges.sh
+10
@@ -250,6 +250,16 @@ test_expect_success 'with a branch tip that was cherry-picked already' '
250 EOF
251 '
252
253 +test_expect_success '--no-rebase-merges countermands --rebase-merges' '
254 + git checkout -b no-rebase-merges E &&
255 + git rebase --rebase-merges --no-rebase-merges C &&
256 + test_cmp_graph C.. <<-\EOF
257 + * B
258 + * D
259 + o C
260 + EOF
261 +'
262 +
263 test_expect_success 'do not rebase cousins unless asked for' '
264 git checkout -b cousins main &&
265 before="$(git rev-parse --verify HEAD)" &&