|
27 | 27 | #include "branch.h" |
28 | 28 |
|
29 | 29 | static char const * const builtin_rebase_usage[] = { |
30 | | - N_("git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] " |
31 | | - "[<upstream>] [<branch>]"), |
| 30 | + N_("git rebase [-i] [options] [--exec <cmd>] " |
| 31 | + "[--onto <newbase> | --keep-base] [<upstream> [<branch>]]"), |
32 | 32 | N_("git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] " |
33 | 33 | "--root [<branch>]"), |
34 | 34 | N_("git rebase --continue | --abort | --skip | --edit-todo"), |
@@ -1039,6 +1039,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) |
1039 | 1039 | }; |
1040 | 1040 | const char *branch_name; |
1041 | 1041 | int ret, flags, total_argc, in_progress = 0; |
| 1042 | + int keep_base = 0; |
1042 | 1043 | int ok_to_skip_pre_rebase = 0; |
1043 | 1044 | struct strbuf msg = STRBUF_INIT; |
1044 | 1045 | struct strbuf revisions = STRBUF_INIT; |
@@ -1072,6 +1073,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) |
1072 | 1073 | OPT_STRING(0, "onto", &options.onto_name, |
1073 | 1074 | N_("revision"), |
1074 | 1075 | N_("rebase onto given branch instead of upstream")), |
| 1076 | + OPT_BOOL(0, "keep-base", &keep_base, |
| 1077 | + N_("use the merge-base of upstream and branch as the current base")), |
1075 | 1078 | OPT_BOOL(0, "no-verify", &ok_to_skip_pre_rebase, |
1076 | 1079 | N_("allow pre-rebase hook to run")), |
1077 | 1080 | OPT_NEGBIT('q', "quiet", &options.flags, |
@@ -1238,6 +1241,13 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) |
1238 | 1241 | usage_with_options(builtin_rebase_usage, |
1239 | 1242 | builtin_rebase_options); |
1240 | 1243 |
|
| 1244 | + if (keep_base) { |
| 1245 | + if (options.onto_name) |
| 1246 | + die(_("cannot combine '--keep-base' with '--onto'")); |
| 1247 | + if (options.root) |
| 1248 | + die(_("cannot combine '--keep-base' with '--root'")); |
| 1249 | + } |
| 1250 | + |
1241 | 1251 | if (action != NO_ACTION && !in_progress) |
1242 | 1252 | die(_("No rebase in progress?")); |
1243 | 1253 | setenv(GIT_REFLOG_ACTION_ENVIRONMENT, "rebase", 0); |
@@ -1562,12 +1572,22 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) |
1562 | 1572 | } |
1563 | 1573 |
|
1564 | 1574 | /* Make sure the branch to rebase onto is valid. */ |
1565 | | - if (!options.onto_name) |
| 1575 | + if (keep_base) { |
| 1576 | + strbuf_reset(&buf); |
| 1577 | + strbuf_addstr(&buf, options.upstream_name); |
| 1578 | + strbuf_addstr(&buf, "..."); |
| 1579 | + options.onto_name = xstrdup(buf.buf); |
| 1580 | + } else if (!options.onto_name) |
1566 | 1581 | options.onto_name = options.upstream_name; |
1567 | 1582 | if (strstr(options.onto_name, "...")) { |
1568 | | - if (get_oid_mb(options.onto_name, &merge_base) < 0) |
1569 | | - die(_("'%s': need exactly one merge base"), |
1570 | | - options.onto_name); |
| 1583 | + if (get_oid_mb(options.onto_name, &merge_base) < 0) { |
| 1584 | + if (keep_base) |
| 1585 | + die(_("'%s': need exactly one merge base with branch"), |
| 1586 | + options.upstream_name); |
| 1587 | + else |
| 1588 | + die(_("'%s': need exactly one merge base"), |
| 1589 | + options.onto_name); |
| 1590 | + } |
1571 | 1591 | options.onto = lookup_commit_or_die(&merge_base, |
1572 | 1592 | options.onto_name); |
1573 | 1593 | } else { |
|
0 commit comments