Skip to content

Commit 8295ed6

Browse files
newrengitster
authored andcommitted
rebase: make the backend configurable via config setting
Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 76340c8 commit 8295ed6

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

Documentation/config/rebase.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ rebase.useBuiltin::
55
is always used. Setting this will emit a warning, to alert any
66
remaining users that setting this now does nothing.
77

8+
rebase.backend::
9+
Default backend to use for rebasing. Possible choices are
10+
'am' or 'merge' (note that the merge backend is sometimes also
11+
refered to as the interactive backend or the interactive
12+
machinery elsewhere in the docs). Also, in the future, if the
13+
merge backend gains all remaining capabilities of the am
14+
backend, this setting may become unused.
15+
816
rebase.stat::
917
Whether to show a diffstat of what changed upstream since the last
1018
rebase. False by default.

builtin/rebase.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ enum empty_type {
6060
struct rebase_options {
6161
enum rebase_type type;
6262
enum empty_type empty;
63+
const char *default_backend;
6364
const char *state_dir;
6465
struct commit *upstream;
6566
const char *upstream_name;
@@ -100,6 +101,7 @@ struct rebase_options {
100101
#define REBASE_OPTIONS_INIT { \
101102
.type = REBASE_UNSPECIFIED, \
102103
.empty = EMPTY_UNSPECIFIED, \
104+
.default_backend = "am", \
103105
.flags = REBASE_NO_QUIET, \
104106
.git_am_opts = ARGV_ARRAY_INIT, \
105107
.git_format_patch_opt = STRBUF_INIT \
@@ -1272,6 +1274,10 @@ static int rebase_config(const char *var, const char *value, void *data)
12721274
return 0;
12731275
}
12741276

1277+
if (!strcmp(var, "rebase.backend")) {
1278+
return git_config_string(&opts->default_backend, var, value);
1279+
}
1280+
12751281
return git_default_config(var, value, data);
12761282
}
12771283

@@ -1900,9 +1906,23 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
19001906
if (strcmp(options.git_am_opts.argv[i], "-q"))
19011907
break;
19021908

1903-
if (is_interactive(&options) && i >= 0)
1904-
die(_("cannot combine am options with either "
1905-
"interactive or merge options"));
1909+
if (i >= 0) {
1910+
if (is_interactive(&options))
1911+
die(_("cannot combine am options with either "
1912+
"interactive or merge options"));
1913+
else
1914+
options.type = REBASE_AM;
1915+
}
1916+
}
1917+
1918+
if (options.type == REBASE_UNSPECIFIED) {
1919+
if (!strcmp(options.default_backend, "merge"))
1920+
options.type = REBASE_MERGE;
1921+
else if (!strcmp(options.default_backend, "am"))
1922+
options.type = REBASE_AM;
1923+
else
1924+
die(_("Unknown rebase backend: %s"),
1925+
options.default_backend);
19061926
}
19071927

19081928
switch (options.type) {
@@ -1915,10 +1935,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
19151935
options.state_dir = apply_dir();
19161936
break;
19171937
default:
1918-
/* the default rebase backend is `--am` */
1919-
options.type = REBASE_AM;
1920-
options.state_dir = apply_dir();
1921-
break;
1938+
BUG("options.type was just set above; should be unreachable.");
19221939
}
19231940

19241941
if (options.empty == EMPTY_UNSPECIFIED) {

0 commit comments

Comments
 (0)