Skip to content

Commit 075bc85

Browse files
prertikgitster
authored andcommitted
builtin rebase: support git rebase --onto A...B
This commit implements support for an --onto argument that is actually a "symmetric range" i.e. `<rev1>...<rev2>`. The equivalent shell script version of the code offers two different error messages for the cases where there is no merge base vs more than one merge base. Though it would be nice to retain this distinction, dropping it makes it possible to simply use the `get_oid_mb()` function. Besides, it happens rarely in real-world scenarios. Therefore, in the interest of keeping the code less complex, let's just use that function, and live with an error message that does not distinguish between those two error conditions. Signed-off-by: Pratik Karki <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f28d40d commit 075bc85

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

builtin/rebase.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "unpack-trees.h"
1818
#include "lockfile.h"
1919
#include "parse-options.h"
20+
#include "commit.h"
2021

2122
static char const * const builtin_rebase_usage[] = {
2223
N_("git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] "
@@ -311,6 +312,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
311312
int ret, flags;
312313
struct strbuf msg = STRBUF_INIT;
313314
struct strbuf revisions = STRBUF_INIT;
315+
struct object_id merge_base;
314316
struct option builtin_rebase_options[] = {
315317
OPT_STRING(0, "onto", &options.onto_name,
316318
N_("revision"),
@@ -387,7 +389,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
387389
if (!options.onto_name)
388390
options.onto_name = options.upstream_name;
389391
if (strstr(options.onto_name, "...")) {
390-
die("TODO");
392+
if (get_oid_mb(options.onto_name, &merge_base) < 0)
393+
die(_("'%s': need exactly one merge base"),
394+
options.onto_name);
395+
options.onto = lookup_commit_or_die(&merge_base,
396+
options.onto_name);
391397
} else {
392398
options.onto = peel_committish(options.onto_name);
393399
if (!options.onto)

0 commit comments

Comments
 (0)