Merge branch 'js/rebase-recreate-merge'
"git rebase" learned "--rebase-merges" to transplant the whole topology of commit graph elsewhere. * js/rebase-recreate-merge: rebase -i --rebase-merges: add a section to the man page rebase -i: introduce --rebase-merges=[no-]rebase-cousins pull: accept --rebase=merges to recreate the branch topology rebase --rebase-merges: avoid "empty merges" sequencer: handle post-rewrite for merge commands sequencer: make refs generated by the `label` command worktree-local rebase --rebase-merges: add test for --keep-empty rebase: introduce the --rebase-merges option rebase-helper --make-script: introduce a flag to rebase merges sequencer: fast-forward `merge` commands, if possible sequencer: introduce the `merge` command sequencer: introduce new commands to reset the revision git-rebase--interactive: clarify arguments sequencer: offer helpful advice when a command was rescheduled sequencer: refactor how original todo list lines are accessed sequencer: make rearrange_squash() a bit more obvious sequencer: avoid using errno clobbered by rollback_lock_file()
This commit is contained in:
@ -1068,6 +1068,10 @@ branch.<name>.rebase::
|
|||||||
"git pull" is run. See "pull.rebase" for doing this in a non
|
"git pull" is run. See "pull.rebase" for doing this in a non
|
||||||
branch-specific manner.
|
branch-specific manner.
|
||||||
+
|
+
|
||||||
|
When `merges`, pass the `--rebase-merges` option to 'git rebase'
|
||||||
|
so that the local merge commits are included in the rebase (see
|
||||||
|
linkgit:git-rebase[1] for details).
|
||||||
|
+
|
||||||
When preserve, also pass `--preserve-merges` along to 'git rebase'
|
When preserve, also pass `--preserve-merges` along to 'git rebase'
|
||||||
so that locally committed merge commits will not be flattened
|
so that locally committed merge commits will not be flattened
|
||||||
by running 'git pull'.
|
by running 'git pull'.
|
||||||
@ -2669,6 +2673,10 @@ pull.rebase::
|
|||||||
pull" is run. See "branch.<name>.rebase" for setting this on a
|
pull" is run. See "branch.<name>.rebase" for setting this on a
|
||||||
per-branch basis.
|
per-branch basis.
|
||||||
+
|
+
|
||||||
|
When `merges`, pass the `--rebase-merges` option to 'git rebase'
|
||||||
|
so that the local merge commits are included in the rebase (see
|
||||||
|
linkgit:git-rebase[1] for details).
|
||||||
|
+
|
||||||
When preserve, also pass `--preserve-merges` along to 'git rebase'
|
When preserve, also pass `--preserve-merges` along to 'git rebase'
|
||||||
so that locally committed merge commits will not be flattened
|
so that locally committed merge commits will not be flattened
|
||||||
by running 'git pull'.
|
by running 'git pull'.
|
||||||
|
@ -101,13 +101,17 @@ Options related to merging
|
|||||||
include::merge-options.txt[]
|
include::merge-options.txt[]
|
||||||
|
|
||||||
-r::
|
-r::
|
||||||
--rebase[=false|true|preserve|interactive]::
|
--rebase[=false|true|merges|preserve|interactive]::
|
||||||
When true, rebase the current branch on top of the upstream
|
When true, rebase the current branch on top of the upstream
|
||||||
branch after fetching. If there is a remote-tracking branch
|
branch after fetching. If there is a remote-tracking branch
|
||||||
corresponding to the upstream branch and the upstream branch
|
corresponding to the upstream branch and the upstream branch
|
||||||
was rebased since last fetched, the rebase uses that information
|
was rebased since last fetched, the rebase uses that information
|
||||||
to avoid rebasing non-local changes.
|
to avoid rebasing non-local changes.
|
||||||
+
|
+
|
||||||
|
When set to `merges`, rebase using `git rebase --rebase-merges` so that
|
||||||
|
the local merge commits are included in the rebase (see
|
||||||
|
linkgit:git-rebase[1] for details).
|
||||||
|
+
|
||||||
When set to preserve, rebase with the `--preserve-merges` option passed
|
When set to preserve, rebase with the `--preserve-merges` option passed
|
||||||
to `git rebase` so that locally created merge commits will not be flattened.
|
to `git rebase` so that locally created merge commits will not be flattened.
|
||||||
+
|
+
|
||||||
|
@ -379,6 +379,33 @@ The commit list format can be changed by setting the configuration option
|
|||||||
rebase.instructionFormat. A customized instruction format will automatically
|
rebase.instructionFormat. A customized instruction format will automatically
|
||||||
have the long commit hash prepended to the format.
|
have the long commit hash prepended to the format.
|
||||||
|
|
||||||
|
-r::
|
||||||
|
--rebase-merges[=(rebase-cousins|no-rebase-cousins)]::
|
||||||
|
By default, a rebase will simply drop merge commits from the todo
|
||||||
|
list, and put the rebased commits into a single, linear branch.
|
||||||
|
With `--rebase-merges`, the rebase will instead try to preserve
|
||||||
|
the branching structure within the commits that are to be rebased,
|
||||||
|
by recreating the merge commits. Any resolved merge conflicts or
|
||||||
|
manual amendments in these merge commits will have to be
|
||||||
|
resolved/re-applied manually.
|
||||||
|
+
|
||||||
|
By default, or when `no-rebase-cousins` was specified, commits which do not
|
||||||
|
have `<upstream>` as direct ancestor will keep their original branch point,
|
||||||
|
i.e. commits that would be excluded by gitlink:git-log[1]'s
|
||||||
|
`--ancestry-path` option will keep their original ancestry by default. If
|
||||||
|
the `rebase-cousins` mode is turned on, such commits are instead rebased
|
||||||
|
onto `<upstream>` (or `<onto>`, if specified).
|
||||||
|
+
|
||||||
|
The `--rebase-merges` mode is similar in spirit to `--preserve-merges`, but
|
||||||
|
in contrast to that option works well in interactive rebases: commits can be
|
||||||
|
reordered, inserted and dropped at will.
|
||||||
|
+
|
||||||
|
It is currently only possible to recreate the merge commits using the
|
||||||
|
`recursive` merge strategy; Different merge strategies can be used only via
|
||||||
|
explicit `exec git merge -s <strategy> [...]` commands.
|
||||||
|
+
|
||||||
|
See also REBASING MERGES below.
|
||||||
|
|
||||||
-p::
|
-p::
|
||||||
--preserve-merges::
|
--preserve-merges::
|
||||||
Recreate merge commits instead of flattening the history by replaying
|
Recreate merge commits instead of flattening the history by replaying
|
||||||
@ -776,12 +803,146 @@ The ripple effect of a "hard case" recovery is especially bad:
|
|||||||
'everyone' downstream from 'topic' will now have to perform a "hard
|
'everyone' downstream from 'topic' will now have to perform a "hard
|
||||||
case" recovery too!
|
case" recovery too!
|
||||||
|
|
||||||
|
REBASING MERGES
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
The interactive rebase command was originally designed to handle
|
||||||
|
individual patch series. As such, it makes sense to exclude merge
|
||||||
|
commits from the todo list, as the developer may have merged the
|
||||||
|
then-current `master` while working on the branch, only to rebase
|
||||||
|
all the commits onto `master` eventually (skipping the merge
|
||||||
|
commits).
|
||||||
|
|
||||||
|
However, there are legitimate reasons why a developer may want to
|
||||||
|
recreate merge commits: to keep the branch structure (or "commit
|
||||||
|
topology") when working on multiple, inter-related branches.
|
||||||
|
|
||||||
|
In the following example, the developer works on a topic branch that
|
||||||
|
refactors the way buttons are defined, and on another topic branch
|
||||||
|
that uses that refactoring to implement a "Report a bug" button. The
|
||||||
|
output of `git log --graph --format=%s -5` may look like this:
|
||||||
|
|
||||||
|
------------
|
||||||
|
* Merge branch 'report-a-bug'
|
||||||
|
|\
|
||||||
|
| * Add the feedback button
|
||||||
|
* | Merge branch 'refactor-button'
|
||||||
|
|\ \
|
||||||
|
| |/
|
||||||
|
| * Use the Button class for all buttons
|
||||||
|
| * Extract a generic Button class from the DownloadButton one
|
||||||
|
------------
|
||||||
|
|
||||||
|
The developer might want to rebase those commits to a newer `master`
|
||||||
|
while keeping the branch topology, for example when the first topic
|
||||||
|
branch is expected to be integrated into `master` much earlier than the
|
||||||
|
second one, say, to resolve merge conflicts with changes to the
|
||||||
|
DownloadButton class that made it into `master`.
|
||||||
|
|
||||||
|
This rebase can be performed using the `--rebase-merges` option.
|
||||||
|
It will generate a todo list looking like this:
|
||||||
|
|
||||||
|
------------
|
||||||
|
label onto
|
||||||
|
|
||||||
|
# Branch: refactor-button
|
||||||
|
reset onto
|
||||||
|
pick 123456 Extract a generic Button class from the DownloadButton one
|
||||||
|
pick 654321 Use the Button class for all buttons
|
||||||
|
label refactor-button
|
||||||
|
|
||||||
|
# Branch: report-a-bug
|
||||||
|
reset refactor-button # Use the Button class for all buttons
|
||||||
|
pick abcdef Add the feedback button
|
||||||
|
label report-a-bug
|
||||||
|
|
||||||
|
reset onto
|
||||||
|
merge -C a1b2c3 refactor-button # Merge 'refactor-button'
|
||||||
|
merge -C 6f5e4d report-a-bug # Merge 'report-a-bug'
|
||||||
|
------------
|
||||||
|
|
||||||
|
In contrast to a regular interactive rebase, there are `label`, `reset`
|
||||||
|
and `merge` commands in addition to `pick` ones.
|
||||||
|
|
||||||
|
The `label` command associates a label with the current HEAD when that
|
||||||
|
command is executed. These labels are created as worktree-local refs
|
||||||
|
(`refs/rewritten/<label>`) that will be deleted when the rebase
|
||||||
|
finishes. That way, rebase operations in multiple worktrees linked to
|
||||||
|
the same repository do not interfere with one another. If the `label`
|
||||||
|
command fails, it is rescheduled immediately, with a helpful message how
|
||||||
|
to proceed.
|
||||||
|
|
||||||
|
The `reset` command resets the HEAD, index and worktree to the specified
|
||||||
|
revision. It is isimilar to an `exec git reset --hard <label>`, but
|
||||||
|
refuses to overwrite untracked files. If the `reset` command fails, it is
|
||||||
|
rescheduled immediately, with a helpful message how to edit the todo list
|
||||||
|
(this typically happens when a `reset` command was inserted into the todo
|
||||||
|
list manually and contains a typo).
|
||||||
|
|
||||||
|
The `merge` command will merge the specified revision into whatever is
|
||||||
|
HEAD at that time. With `-C <original-commit>`, the commit message of
|
||||||
|
the specified merge commit will be used. When the `-C` is changed to
|
||||||
|
a lower-case `-c`, the message will be opened in an editor after a
|
||||||
|
successful merge so that the user can edit the message.
|
||||||
|
|
||||||
|
If a `merge` command fails for any reason other than merge conflicts (i.e.
|
||||||
|
when the merge operation did not even start), it is rescheduled immediately.
|
||||||
|
|
||||||
|
At this time, the `merge` command will *always* use the `recursive`
|
||||||
|
merge strategy, with no way to choose a different one. To work around
|
||||||
|
this, an `exec` command can be used to call `git merge` explicitly,
|
||||||
|
using the fact that the labels are worktree-local refs (the ref
|
||||||
|
`refs/rewritten/onto` would correspond to the label `onto`, for example).
|
||||||
|
|
||||||
|
Note: the first command (`label onto`) labels the revision onto which
|
||||||
|
the commits are rebased; The name `onto` is just a convention, as a nod
|
||||||
|
to the `--onto` option.
|
||||||
|
|
||||||
|
It is also possible to introduce completely new merge commits from scratch
|
||||||
|
by adding a command of the form `merge <merge-head>`. This form will
|
||||||
|
generate a tentative commit message and always open an editor to let the
|
||||||
|
user edit it. This can be useful e.g. when a topic branch turns out to
|
||||||
|
address more than a single concern and wants to be split into two or
|
||||||
|
even more topic branches. Consider this todo list:
|
||||||
|
|
||||||
|
------------
|
||||||
|
pick 192837 Switch from GNU Makefiles to CMake
|
||||||
|
pick 5a6c7e Document the switch to CMake
|
||||||
|
pick 918273 Fix detection of OpenSSL in CMake
|
||||||
|
pick afbecd http: add support for TLS v1.3
|
||||||
|
pick fdbaec Fix detection of cURL in CMake on Windows
|
||||||
|
------------
|
||||||
|
|
||||||
|
The one commit in this list that is not related to CMake may very well
|
||||||
|
have been motivated by working on fixing all those bugs introduced by
|
||||||
|
switching to CMake, but it addresses a different concern. To split this
|
||||||
|
branch into two topic branches, the todo list could be edited like this:
|
||||||
|
|
||||||
|
------------
|
||||||
|
label onto
|
||||||
|
|
||||||
|
pick afbecd http: add support for TLS v1.3
|
||||||
|
label tlsv1.3
|
||||||
|
|
||||||
|
reset onto
|
||||||
|
pick 192837 Switch from GNU Makefiles to CMake
|
||||||
|
pick 918273 Fix detection of OpenSSL in CMake
|
||||||
|
pick fdbaec Fix detection of cURL in CMake on Windows
|
||||||
|
pick 5a6c7e Document the switch to CMake
|
||||||
|
label cmake
|
||||||
|
|
||||||
|
reset onto
|
||||||
|
merge tlsv1.3
|
||||||
|
merge cmake
|
||||||
|
------------
|
||||||
|
|
||||||
BUGS
|
BUGS
|
||||||
----
|
----
|
||||||
The todo list presented by `--preserve-merges --interactive` does not
|
The todo list presented by `--preserve-merges --interactive` does not
|
||||||
represent the topology of the revision graph. Editing commits and
|
represent the topology of the revision graph. Editing commits and
|
||||||
rewording their commit messages should work fine, but attempts to
|
rewording their commit messages should work fine, but attempts to
|
||||||
reorder commits tend to produce counterintuitive results.
|
reorder commits tend to produce counterintuitive results. Use
|
||||||
|
`--rebase-merges` in such scenarios instead.
|
||||||
|
|
||||||
For example, an attempt to rearrange
|
For example, an attempt to rearrange
|
||||||
------------
|
------------
|
||||||
|
@ -27,14 +27,16 @@ enum rebase_type {
|
|||||||
REBASE_FALSE = 0,
|
REBASE_FALSE = 0,
|
||||||
REBASE_TRUE,
|
REBASE_TRUE,
|
||||||
REBASE_PRESERVE,
|
REBASE_PRESERVE,
|
||||||
|
REBASE_MERGES,
|
||||||
REBASE_INTERACTIVE
|
REBASE_INTERACTIVE
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the value of --rebase. If value is a false value, returns
|
* Parses the value of --rebase. If value is a false value, returns
|
||||||
* REBASE_FALSE. If value is a true value, returns REBASE_TRUE. If value is
|
* REBASE_FALSE. If value is a true value, returns REBASE_TRUE. If value is
|
||||||
* "preserve", returns REBASE_PRESERVE. If value is a invalid value, dies with
|
* "merges", returns REBASE_MERGES. If value is "preserve", returns
|
||||||
* a fatal error if fatal is true, otherwise returns REBASE_INVALID.
|
* REBASE_PRESERVE. If value is a invalid value, dies with a fatal error if
|
||||||
|
* fatal is true, otherwise returns REBASE_INVALID.
|
||||||
*/
|
*/
|
||||||
static enum rebase_type parse_config_rebase(const char *key, const char *value,
|
static enum rebase_type parse_config_rebase(const char *key, const char *value,
|
||||||
int fatal)
|
int fatal)
|
||||||
@ -47,6 +49,8 @@ static enum rebase_type parse_config_rebase(const char *key, const char *value,
|
|||||||
return REBASE_TRUE;
|
return REBASE_TRUE;
|
||||||
else if (!strcmp(value, "preserve"))
|
else if (!strcmp(value, "preserve"))
|
||||||
return REBASE_PRESERVE;
|
return REBASE_PRESERVE;
|
||||||
|
else if (!strcmp(value, "merges"))
|
||||||
|
return REBASE_MERGES;
|
||||||
else if (!strcmp(value, "interactive"))
|
else if (!strcmp(value, "interactive"))
|
||||||
return REBASE_INTERACTIVE;
|
return REBASE_INTERACTIVE;
|
||||||
|
|
||||||
@ -130,7 +134,7 @@ static struct option pull_options[] = {
|
|||||||
/* Options passed to git-merge or git-rebase */
|
/* Options passed to git-merge or git-rebase */
|
||||||
OPT_GROUP(N_("Options related to merging")),
|
OPT_GROUP(N_("Options related to merging")),
|
||||||
{ OPTION_CALLBACK, 'r', "rebase", &opt_rebase,
|
{ OPTION_CALLBACK, 'r', "rebase", &opt_rebase,
|
||||||
"false|true|preserve|interactive",
|
"false|true|merges|preserve|interactive",
|
||||||
N_("incorporate changes by rebasing rather than merging"),
|
N_("incorporate changes by rebasing rather than merging"),
|
||||||
PARSE_OPT_OPTARG, parse_opt_rebase },
|
PARSE_OPT_OPTARG, parse_opt_rebase },
|
||||||
OPT_PASSTHRU('n', NULL, &opt_diffstat, NULL,
|
OPT_PASSTHRU('n', NULL, &opt_diffstat, NULL,
|
||||||
@ -800,7 +804,9 @@ static int run_rebase(const struct object_id *curr_head,
|
|||||||
argv_push_verbosity(&args);
|
argv_push_verbosity(&args);
|
||||||
|
|
||||||
/* Options passed to git-rebase */
|
/* Options passed to git-rebase */
|
||||||
if (opt_rebase == REBASE_PRESERVE)
|
if (opt_rebase == REBASE_MERGES)
|
||||||
|
argv_array_push(&args, "--rebase-merges");
|
||||||
|
else if (opt_rebase == REBASE_PRESERVE)
|
||||||
argv_array_push(&args, "--preserve-merges");
|
argv_array_push(&args, "--preserve-merges");
|
||||||
else if (opt_rebase == REBASE_INTERACTIVE)
|
else if (opt_rebase == REBASE_INTERACTIVE)
|
||||||
argv_array_push(&args, "--interactive");
|
argv_array_push(&args, "--interactive");
|
||||||
|
@ -12,8 +12,8 @@ static const char * const builtin_rebase_helper_usage[] = {
|
|||||||
int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
|
int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
|
||||||
{
|
{
|
||||||
struct replay_opts opts = REPLAY_OPTS_INIT;
|
struct replay_opts opts = REPLAY_OPTS_INIT;
|
||||||
unsigned flags = 0, keep_empty = 0;
|
unsigned flags = 0, keep_empty = 0, rebase_merges = 0;
|
||||||
int abbreviate_commands = 0;
|
int abbreviate_commands = 0, rebase_cousins = -1;
|
||||||
enum {
|
enum {
|
||||||
CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS,
|
CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS,
|
||||||
CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH,
|
CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH,
|
||||||
@ -24,6 +24,9 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
|
|||||||
OPT_BOOL(0, "keep-empty", &keep_empty, N_("keep empty commits")),
|
OPT_BOOL(0, "keep-empty", &keep_empty, N_("keep empty commits")),
|
||||||
OPT_BOOL(0, "allow-empty-message", &opts.allow_empty_message,
|
OPT_BOOL(0, "allow-empty-message", &opts.allow_empty_message,
|
||||||
N_("allow commits with empty messages")),
|
N_("allow commits with empty messages")),
|
||||||
|
OPT_BOOL(0, "rebase-merges", &rebase_merges, N_("rebase merge commits")),
|
||||||
|
OPT_BOOL(0, "rebase-cousins", &rebase_cousins,
|
||||||
|
N_("keep original branch points of cousins")),
|
||||||
OPT_CMDMODE(0, "continue", &command, N_("continue rebase"),
|
OPT_CMDMODE(0, "continue", &command, N_("continue rebase"),
|
||||||
CONTINUE),
|
CONTINUE),
|
||||||
OPT_CMDMODE(0, "abort", &command, N_("abort rebase"),
|
OPT_CMDMODE(0, "abort", &command, N_("abort rebase"),
|
||||||
@ -57,8 +60,14 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
flags |= keep_empty ? TODO_LIST_KEEP_EMPTY : 0;
|
flags |= keep_empty ? TODO_LIST_KEEP_EMPTY : 0;
|
||||||
flags |= abbreviate_commands ? TODO_LIST_ABBREVIATE_CMDS : 0;
|
flags |= abbreviate_commands ? TODO_LIST_ABBREVIATE_CMDS : 0;
|
||||||
|
flags |= rebase_merges ? TODO_LIST_REBASE_MERGES : 0;
|
||||||
|
flags |= rebase_cousins > 0 ? TODO_LIST_REBASE_COUSINS : 0;
|
||||||
flags |= command == SHORTEN_OIDS ? TODO_LIST_SHORTEN_IDS : 0;
|
flags |= command == SHORTEN_OIDS ? TODO_LIST_SHORTEN_IDS : 0;
|
||||||
|
|
||||||
|
if (rebase_cousins >= 0 && !rebase_merges)
|
||||||
|
warning(_("--[no-]rebase-cousins has no effect without "
|
||||||
|
"--rebase-merges"));
|
||||||
|
|
||||||
if (command == CONTINUE && argc == 1)
|
if (command == CONTINUE && argc == 1)
|
||||||
return !!sequencer_continue(&opts);
|
return !!sequencer_continue(&opts);
|
||||||
if (command == ABORT && argc == 1)
|
if (command == ABORT && argc == 1)
|
||||||
|
@ -245,7 +245,9 @@ static int add(int argc, const char **argv)
|
|||||||
struct branch_info {
|
struct branch_info {
|
||||||
char *remote_name;
|
char *remote_name;
|
||||||
struct string_list merge;
|
struct string_list merge;
|
||||||
enum { NO_REBASE, NORMAL_REBASE, INTERACTIVE_REBASE } rebase;
|
enum {
|
||||||
|
NO_REBASE, NORMAL_REBASE, INTERACTIVE_REBASE, REBASE_MERGES
|
||||||
|
} rebase;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct string_list branch_list = STRING_LIST_INIT_NODUP;
|
static struct string_list branch_list = STRING_LIST_INIT_NODUP;
|
||||||
@ -306,6 +308,8 @@ static int config_read_branches(const char *key, const char *value, void *cb)
|
|||||||
info->rebase = v;
|
info->rebase = v;
|
||||||
else if (!strcmp(value, "preserve"))
|
else if (!strcmp(value, "preserve"))
|
||||||
info->rebase = NORMAL_REBASE;
|
info->rebase = NORMAL_REBASE;
|
||||||
|
else if (!strcmp(value, "merges"))
|
||||||
|
info->rebase = REBASE_MERGES;
|
||||||
else if (!strcmp(value, "interactive"))
|
else if (!strcmp(value, "interactive"))
|
||||||
info->rebase = INTERACTIVE_REBASE;
|
info->rebase = INTERACTIVE_REBASE;
|
||||||
}
|
}
|
||||||
@ -963,9 +967,15 @@ static int show_local_info_item(struct string_list_item *item, void *cb_data)
|
|||||||
|
|
||||||
printf(" %-*s ", show_info->width, item->string);
|
printf(" %-*s ", show_info->width, item->string);
|
||||||
if (branch_info->rebase) {
|
if (branch_info->rebase) {
|
||||||
printf_ln(branch_info->rebase == INTERACTIVE_REBASE
|
const char *msg;
|
||||||
? _("rebases interactively onto remote %s")
|
if (branch_info->rebase == INTERACTIVE_REBASE)
|
||||||
: _("rebases onto remote %s"), merge->items[0].string);
|
msg = _("rebases interactively onto remote %s");
|
||||||
|
else if (branch_info->rebase == REBASE_MERGES)
|
||||||
|
msg = _("rebases interactively (with merges) onto "
|
||||||
|
"remote %s");
|
||||||
|
else
|
||||||
|
msg = _("rebases onto remote %s");
|
||||||
|
printf_ln(msg, merge->items[0].string);
|
||||||
return 0;
|
return 0;
|
||||||
} else if (show_info->any_rebase) {
|
} else if (show_info->any_rebase) {
|
||||||
printf_ln(_(" merges with remote %s"), merge->items[0].string);
|
printf_ln(_(" merges with remote %s"), merge->items[0].string);
|
||||||
|
@ -1949,7 +1949,7 @@ _git_rebase ()
|
|||||||
--*)
|
--*)
|
||||||
__gitcomp "
|
__gitcomp "
|
||||||
--onto --merge --strategy --interactive
|
--onto --merge --strategy --interactive
|
||||||
--preserve-merges --stat --no-stat
|
--rebase-merges --preserve-merges --stat --no-stat
|
||||||
--committer-date-is-author-date --ignore-date
|
--committer-date-is-author-date --ignore-date
|
||||||
--ignore-whitespace --whitespace=
|
--ignore-whitespace --whitespace=
|
||||||
--autosquash --no-autosquash
|
--autosquash --no-autosquash
|
||||||
@ -2120,7 +2120,7 @@ _git_config ()
|
|||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
branch.*.rebase)
|
branch.*.rebase)
|
||||||
__gitcomp "false true preserve interactive"
|
__gitcomp "false true merges preserve interactive"
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
remote.pushdefault)
|
remote.pushdefault)
|
||||||
|
@ -155,13 +155,19 @@ reschedule_last_action () {
|
|||||||
append_todo_help () {
|
append_todo_help () {
|
||||||
gettext "
|
gettext "
|
||||||
Commands:
|
Commands:
|
||||||
p, pick = use commit
|
p, pick <commit> = use commit
|
||||||
r, reword = use commit, but edit the commit message
|
r, reword <commit> = use commit, but edit the commit message
|
||||||
e, edit = use commit, but stop for amending
|
e, edit <commit> = use commit, but stop for amending
|
||||||
s, squash = use commit, but meld into previous commit
|
s, squash <commit> = use commit, but meld into previous commit
|
||||||
f, fixup = like \"squash\", but discard this commit's log message
|
f, fixup <commit> = like \"squash\", but discard this commit's log message
|
||||||
x, exec = run command (the rest of the line) using shell
|
x, exec <commit> = run command (the rest of the line) using shell
|
||||||
d, drop = remove commit
|
d, drop <commit> = remove commit
|
||||||
|
l, label <label> = label current HEAD with a name
|
||||||
|
t, reset <label> = reset HEAD to a label
|
||||||
|
m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
|
||||||
|
. create a merge commit using the original merge commit's
|
||||||
|
. message (or the oneline, if no original merge commit was
|
||||||
|
. specified). Use -c <commit> to reword the commit message.
|
||||||
|
|
||||||
These lines can be re-ordered; they are executed from top to bottom.
|
These lines can be re-ordered; they are executed from top to bottom.
|
||||||
" | git stripspace --comment-lines >>"$todo"
|
" | git stripspace --comment-lines >>"$todo"
|
||||||
@ -964,6 +970,8 @@ git_rebase__interactive () {
|
|||||||
init_revisions_and_shortrevisions
|
init_revisions_and_shortrevisions
|
||||||
|
|
||||||
git rebase--helper --make-script ${keep_empty:+--keep-empty} \
|
git rebase--helper --make-script ${keep_empty:+--keep-empty} \
|
||||||
|
${rebase_merges:+--rebase-merges} \
|
||||||
|
${rebase_cousins:+--rebase-cousins} \
|
||||||
$revisions ${restrict_revision+^$restrict_revision} >"$todo" ||
|
$revisions ${restrict_revision+^$restrict_revision} >"$todo" ||
|
||||||
die "$(gettext "Could not generate todo list")"
|
die "$(gettext "Could not generate todo list")"
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ q,quiet! be quiet. implies --no-stat
|
|||||||
autostash automatically stash/stash pop before and after
|
autostash automatically stash/stash pop before and after
|
||||||
fork-point use 'merge-base --fork-point' to refine upstream
|
fork-point use 'merge-base --fork-point' to refine upstream
|
||||||
onto=! rebase onto given branch instead of upstream
|
onto=! rebase onto given branch instead of upstream
|
||||||
|
r,rebase-merges? try to rebase merges instead of skipping them
|
||||||
p,preserve-merges! try to recreate merges instead of ignoring them
|
p,preserve-merges! try to recreate merges instead of ignoring them
|
||||||
s,strategy=! use the given merge strategy
|
s,strategy=! use the given merge strategy
|
||||||
no-ff! cherry-pick all commits, even if unchanged
|
no-ff! cherry-pick all commits, even if unchanged
|
||||||
@ -89,6 +90,8 @@ type=
|
|||||||
state_dir=
|
state_dir=
|
||||||
# One of {'', continue, skip, abort}, as parsed from command line
|
# One of {'', continue, skip, abort}, as parsed from command line
|
||||||
action=
|
action=
|
||||||
|
rebase_merges=
|
||||||
|
rebase_cousins=
|
||||||
preserve_merges=
|
preserve_merges=
|
||||||
autosquash=
|
autosquash=
|
||||||
keep_empty=
|
keep_empty=
|
||||||
@ -280,6 +283,19 @@ do
|
|||||||
--no-keep-empty)
|
--no-keep-empty)
|
||||||
keep_empty=
|
keep_empty=
|
||||||
;;
|
;;
|
||||||
|
--rebase-merges)
|
||||||
|
rebase_merges=t
|
||||||
|
test -z "$interactive_rebase" && interactive_rebase=implied
|
||||||
|
;;
|
||||||
|
--rebase-merges=*)
|
||||||
|
rebase_merges=t
|
||||||
|
case "${1#*=}" in
|
||||||
|
rebase-cousins) rebase_cousins=t;;
|
||||||
|
no-rebase-cousins) rebase_cousins=;;
|
||||||
|
*) die "Unknown mode: $1";;
|
||||||
|
esac
|
||||||
|
test -z "$interactive_rebase" && interactive_rebase=implied
|
||||||
|
;;
|
||||||
--preserve-merges)
|
--preserve-merges)
|
||||||
preserve_merges=t
|
preserve_merges=t
|
||||||
test -z "$interactive_rebase" && interactive_rebase=implied
|
test -z "$interactive_rebase" && interactive_rebase=implied
|
||||||
|
3
refs.c
3
refs.c
@ -615,7 +615,8 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)
|
|||||||
static int is_per_worktree_ref(const char *refname)
|
static int is_per_worktree_ref(const char *refname)
|
||||||
{
|
{
|
||||||
return !strcmp(refname, "HEAD") ||
|
return !strcmp(refname, "HEAD") ||
|
||||||
starts_with(refname, "refs/bisect/");
|
starts_with(refname, "refs/bisect/") ||
|
||||||
|
starts_with(refname, "refs/rewritten/");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int is_pseudoref_syntax(const char *refname)
|
static int is_pseudoref_syntax(const char *refname)
|
||||||
|
892
sequencer.c
892
sequencer.c
File diff suppressed because it is too large
Load Diff
@ -63,6 +63,13 @@ int sequencer_remove_state(struct replay_opts *opts);
|
|||||||
#define TODO_LIST_KEEP_EMPTY (1U << 0)
|
#define TODO_LIST_KEEP_EMPTY (1U << 0)
|
||||||
#define TODO_LIST_SHORTEN_IDS (1U << 1)
|
#define TODO_LIST_SHORTEN_IDS (1U << 1)
|
||||||
#define TODO_LIST_ABBREVIATE_CMDS (1U << 2)
|
#define TODO_LIST_ABBREVIATE_CMDS (1U << 2)
|
||||||
|
#define TODO_LIST_REBASE_MERGES (1U << 3)
|
||||||
|
/*
|
||||||
|
* When rebasing merges, commits that do have the base commit as ancestor
|
||||||
|
* ("cousins") are *not* rebased onto the new base by default. If those
|
||||||
|
* commits should be rebased onto the new base, this flag needs to be passed.
|
||||||
|
*/
|
||||||
|
#define TODO_LIST_REBASE_COUSINS (1U << 4)
|
||||||
int sequencer_make_script(FILE *out, int argc, const char **argv,
|
int sequencer_make_script(FILE *out, int argc, const char **argv,
|
||||||
unsigned flags);
|
unsigned flags);
|
||||||
|
|
||||||
|
@ -217,6 +217,7 @@ test_run_rebase success ''
|
|||||||
test_run_rebase success -m
|
test_run_rebase success -m
|
||||||
test_run_rebase success -i
|
test_run_rebase success -i
|
||||||
test_run_rebase failure -p
|
test_run_rebase failure -p
|
||||||
|
test_run_rebase success --rebase-merges
|
||||||
|
|
||||||
# m
|
# m
|
||||||
# /
|
# /
|
||||||
|
244
t/t3430-rebase-merges.sh
Executable file
244
t/t3430-rebase-merges.sh
Executable file
@ -0,0 +1,244 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Copyright (c) 2018 Johannes E. Schindelin
|
||||||
|
#
|
||||||
|
|
||||||
|
test_description='git rebase -i --rebase-merges
|
||||||
|
|
||||||
|
This test runs git rebase "interactively", retaining the branch structure by
|
||||||
|
recreating merge commits.
|
||||||
|
|
||||||
|
Initial setup:
|
||||||
|
|
||||||
|
-- B -- (first)
|
||||||
|
/ \
|
||||||
|
A - C - D - E - H (master)
|
||||||
|
\ /
|
||||||
|
F - G (second)
|
||||||
|
'
|
||||||
|
. ./test-lib.sh
|
||||||
|
. "$TEST_DIRECTORY"/lib-rebase.sh
|
||||||
|
|
||||||
|
test_cmp_graph () {
|
||||||
|
cat >expect &&
|
||||||
|
git log --graph --boundary --format=%s "$@" >output &&
|
||||||
|
sed "s/ *$//" <output >output.trimmed &&
|
||||||
|
test_cmp expect output.trimmed
|
||||||
|
}
|
||||||
|
|
||||||
|
test_expect_success 'setup' '
|
||||||
|
write_script replace-editor.sh <<-\EOF &&
|
||||||
|
mv "$1" "$(git rev-parse --git-path ORIGINAL-TODO)"
|
||||||
|
cp script-from-scratch "$1"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_commit A &&
|
||||||
|
git checkout -b first &&
|
||||||
|
test_commit B &&
|
||||||
|
git checkout master &&
|
||||||
|
test_commit C &&
|
||||||
|
test_commit D &&
|
||||||
|
git merge --no-commit B &&
|
||||||
|
test_tick &&
|
||||||
|
git commit -m E &&
|
||||||
|
git tag -m E E &&
|
||||||
|
git checkout -b second C &&
|
||||||
|
test_commit F &&
|
||||||
|
test_commit G &&
|
||||||
|
git checkout master &&
|
||||||
|
git merge --no-commit G &&
|
||||||
|
test_tick &&
|
||||||
|
git commit -m H &&
|
||||||
|
git tag -m H H
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'create completely different structure' '
|
||||||
|
cat >script-from-scratch <<-\EOF &&
|
||||||
|
label onto
|
||||||
|
|
||||||
|
# onebranch
|
||||||
|
pick G
|
||||||
|
pick D
|
||||||
|
label onebranch
|
||||||
|
|
||||||
|
# second
|
||||||
|
reset onto
|
||||||
|
pick B
|
||||||
|
label second
|
||||||
|
|
||||||
|
reset onto
|
||||||
|
merge -C H second
|
||||||
|
merge onebranch # Merge the topic branch '\''onebranch'\''
|
||||||
|
EOF
|
||||||
|
test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
|
||||||
|
test_tick &&
|
||||||
|
git rebase -i -r A &&
|
||||||
|
test_cmp_graph <<-\EOF
|
||||||
|
* Merge the topic branch '\''onebranch'\''
|
||||||
|
|\
|
||||||
|
| * D
|
||||||
|
| * G
|
||||||
|
* | H
|
||||||
|
|\ \
|
||||||
|
| |/
|
||||||
|
|/|
|
||||||
|
| * B
|
||||||
|
|/
|
||||||
|
* A
|
||||||
|
EOF
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'generate correct todo list' '
|
||||||
|
cat >expect <<-\EOF &&
|
||||||
|
label onto
|
||||||
|
|
||||||
|
reset onto
|
||||||
|
pick d9df450 B
|
||||||
|
label E
|
||||||
|
|
||||||
|
reset onto
|
||||||
|
pick 5dee784 C
|
||||||
|
label branch-point
|
||||||
|
pick ca2c861 F
|
||||||
|
pick 088b00a G
|
||||||
|
label H
|
||||||
|
|
||||||
|
reset branch-point # C
|
||||||
|
pick 12bd07b D
|
||||||
|
merge -C 2051b56 E # E
|
||||||
|
merge -C 233d48a H # H
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
grep -v "^#" <.git/ORIGINAL-TODO >output &&
|
||||||
|
test_cmp expect output
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success '`reset` refuses to overwrite untracked files' '
|
||||||
|
git checkout -b refuse-to-reset &&
|
||||||
|
test_commit dont-overwrite-untracked &&
|
||||||
|
git checkout @{-1} &&
|
||||||
|
: >dont-overwrite-untracked.t &&
|
||||||
|
echo "reset refs/tags/dont-overwrite-untracked" >script-from-scratch &&
|
||||||
|
test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
|
||||||
|
test_must_fail git rebase -r HEAD &&
|
||||||
|
git rebase --abort
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'failed `merge` writes patch (may be rescheduled, too)' '
|
||||||
|
test_when_finished "test_might_fail git rebase --abort" &&
|
||||||
|
git checkout -b conflicting-merge A &&
|
||||||
|
|
||||||
|
: fail because of conflicting untracked file &&
|
||||||
|
>G.t &&
|
||||||
|
echo "merge -C H G" >script-from-scratch &&
|
||||||
|
test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
|
||||||
|
test_tick &&
|
||||||
|
test_must_fail git rebase -ir HEAD &&
|
||||||
|
grep "^merge -C .* G$" .git/rebase-merge/done &&
|
||||||
|
grep "^merge -C .* G$" .git/rebase-merge/git-rebase-todo &&
|
||||||
|
test_path_is_file .git/rebase-merge/patch &&
|
||||||
|
|
||||||
|
: fail because of merge conflict &&
|
||||||
|
rm G.t .git/rebase-merge/patch &&
|
||||||
|
git reset --hard &&
|
||||||
|
test_commit conflicting-G G.t not-G conflicting-G &&
|
||||||
|
test_must_fail git rebase --continue &&
|
||||||
|
! grep "^merge -C .* G$" .git/rebase-merge/git-rebase-todo &&
|
||||||
|
test_path_is_file .git/rebase-merge/patch
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'with a branch tip that was cherry-picked already' '
|
||||||
|
git checkout -b already-upstream master &&
|
||||||
|
base="$(git rev-parse --verify HEAD)" &&
|
||||||
|
|
||||||
|
test_commit A1 &&
|
||||||
|
test_commit A2 &&
|
||||||
|
git reset --hard $base &&
|
||||||
|
test_commit B1 &&
|
||||||
|
test_tick &&
|
||||||
|
git merge -m "Merge branch A" A2 &&
|
||||||
|
|
||||||
|
git checkout -b upstream-with-a2 $base &&
|
||||||
|
test_tick &&
|
||||||
|
git cherry-pick A2 &&
|
||||||
|
|
||||||
|
git checkout already-upstream &&
|
||||||
|
test_tick &&
|
||||||
|
git rebase -i -r upstream-with-a2 &&
|
||||||
|
test_cmp_graph upstream-with-a2.. <<-\EOF
|
||||||
|
* Merge branch A
|
||||||
|
|\
|
||||||
|
| * A1
|
||||||
|
* | B1
|
||||||
|
|/
|
||||||
|
o A2
|
||||||
|
EOF
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'do not rebase cousins unless asked for' '
|
||||||
|
git checkout -b cousins master &&
|
||||||
|
before="$(git rev-parse --verify HEAD)" &&
|
||||||
|
test_tick &&
|
||||||
|
git rebase -r HEAD^ &&
|
||||||
|
test_cmp_rev HEAD $before &&
|
||||||
|
test_tick &&
|
||||||
|
git rebase --rebase-merges=rebase-cousins HEAD^ &&
|
||||||
|
test_cmp_graph HEAD^.. <<-\EOF
|
||||||
|
* Merge the topic branch '\''onebranch'\''
|
||||||
|
|\
|
||||||
|
| * D
|
||||||
|
| * G
|
||||||
|
|/
|
||||||
|
o H
|
||||||
|
EOF
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'refs/rewritten/* is worktree-local' '
|
||||||
|
git worktree add wt &&
|
||||||
|
cat >wt/script-from-scratch <<-\EOF &&
|
||||||
|
label xyz
|
||||||
|
exec GIT_DIR=../.git git rev-parse --verify refs/rewritten/xyz >a || :
|
||||||
|
exec git rev-parse --verify refs/rewritten/xyz >b
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_config -C wt sequence.editor \""$PWD"/replace-editor.sh\" &&
|
||||||
|
git -C wt rebase -i HEAD &&
|
||||||
|
test_must_be_empty wt/a &&
|
||||||
|
test_cmp_rev HEAD "$(cat wt/b)"
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'post-rewrite hook and fixups work for merges' '
|
||||||
|
git checkout -b post-rewrite &&
|
||||||
|
test_commit same1 &&
|
||||||
|
git reset --hard HEAD^ &&
|
||||||
|
test_commit same2 &&
|
||||||
|
git merge -m "to fix up" same1 &&
|
||||||
|
echo same old same old >same2.t &&
|
||||||
|
test_tick &&
|
||||||
|
git commit --fixup HEAD same2.t &&
|
||||||
|
fixup="$(git rev-parse HEAD)" &&
|
||||||
|
|
||||||
|
mkdir -p .git/hooks &&
|
||||||
|
test_when_finished "rm .git/hooks/post-rewrite" &&
|
||||||
|
echo "cat >actual" | write_script .git/hooks/post-rewrite &&
|
||||||
|
|
||||||
|
test_tick &&
|
||||||
|
git rebase -i --autosquash -r HEAD^^^ &&
|
||||||
|
printf "%s %s\n%s %s\n%s %s\n%s %s\n" >expect $(git rev-parse \
|
||||||
|
$fixup^^2 HEAD^2 \
|
||||||
|
$fixup^^ HEAD^ \
|
||||||
|
$fixup^ HEAD \
|
||||||
|
$fixup HEAD) &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'refuse to merge ancestors of HEAD' '
|
||||||
|
echo "merge HEAD^" >script-from-scratch &&
|
||||||
|
test_config -C wt sequence.editor \""$PWD"/replace-editor.sh\" &&
|
||||||
|
before="$(git rev-parse HEAD)" &&
|
||||||
|
git rebase -i HEAD &&
|
||||||
|
test_cmp_rev HEAD $before
|
||||||
|
'
|
||||||
|
|
||||||
|
test_done
|
Reference in New Issue
Block a user