Skip to content

Commit 682bbad

Browse files
committed
Merge branch 'ah/rebase-no-fork-point-config'
"git rebase --[no-]fork-point" gained a configuration variable rebase.forkPoint so that users do not have to keep specifying a non-default setting. * ah/rebase-no-fork-point-config: rebase: add a config option for --no-fork-point
2 parents 628c13c + 2803d80 commit 682bbad

File tree

3 files changed

+61
-17
lines changed

3 files changed

+61
-17
lines changed

Documentation/config/rebase.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,6 @@ rebase.rescheduleFailedExec::
6868
Automatically reschedule `exec` commands that failed. This only makes
6969
sense in interactive mode (or when an `--exec` option was provided).
7070
This is the same as specifying the `--reschedule-failed-exec` option.
71+
72+
rebase.forkPoint::
73+
If set to false set `--no-fork-point` option by default.

builtin/rebase.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ struct rebase_options {
102102
int reschedule_failed_exec;
103103
int use_legacy_rebase;
104104
int reapply_cherry_picks;
105+
int fork_point;
105106
};
106107

107108
#define REBASE_OPTIONS_INIT { \
@@ -111,7 +112,8 @@ struct rebase_options {
111112
.default_backend = "merge", \
112113
.flags = REBASE_NO_QUIET, \
113114
.git_am_opts = STRVEC_INIT, \
114-
.git_format_patch_opt = STRBUF_INIT \
115+
.git_format_patch_opt = STRBUF_INIT, \
116+
.fork_point = -1, \
115117
}
116118

117119
static struct replay_opts get_replay_opts(const struct rebase_options *opts)
@@ -1095,6 +1097,11 @@ static int rebase_config(const char *var, const char *value, void *data)
10951097
return 0;
10961098
}
10971099

1100+
if (!strcmp(var, "rebase.forkpoint")) {
1101+
opts->fork_point = git_config_bool(var, value) ? -1 : 0;
1102+
return 0;
1103+
}
1104+
10981105
if (!strcmp(var, "rebase.usebuiltin")) {
10991106
opts->use_legacy_rebase = !git_config_bool(var, value);
11001107
return 0;
@@ -1306,7 +1313,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
13061313
const char *gpg_sign = NULL;
13071314
struct string_list exec = STRING_LIST_INIT_NODUP;
13081315
const char *rebase_merges = NULL;
1309-
int fork_point = -1;
13101316
struct string_list strategy_options = STRING_LIST_INIT_NODUP;
13111317
struct object_id squash_onto;
13121318
char *squash_onto_name = NULL;
@@ -1406,7 +1412,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
14061412
N_("mode"),
14071413
N_("try to rebase merges instead of skipping them"),
14081414
PARSE_OPT_OPTARG, NULL, (intptr_t)""},
1409-
OPT_BOOL(0, "fork-point", &fork_point,
1415+
OPT_BOOL(0, "fork-point", &options.fork_point,
14101416
N_("use 'merge-base --fork-point' to refine upstream")),
14111417
OPT_STRING('s', "strategy", &options.strategy,
14121418
N_("strategy"), N_("use the given merge strategy")),
@@ -1494,7 +1500,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
14941500
die(_("cannot combine '--keep-base' with '--root'"));
14951501
}
14961502

1497-
if (options.root && fork_point > 0)
1503+
if (options.root && options.fork_point > 0)
14981504
die(_("cannot combine '--root' with '--fork-point'"));
14991505

15001506
if (action != ACTION_NONE && !in_progress)
@@ -1840,8 +1846,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
18401846
NULL);
18411847
if (!options.upstream_name)
18421848
error_on_missing_default_upstream();
1843-
if (fork_point < 0)
1844-
fork_point = 1;
1849+
if (options.fork_point < 0)
1850+
options.fork_point = 1;
18451851
} else {
18461852
options.upstream_name = argv[0];
18471853
argc--;
@@ -1945,7 +1951,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
19451951
} else
19461952
BUG("unexpected number of arguments left to parse");
19471953

1948-
if (fork_point > 0) {
1954+
if (options.fork_point > 0) {
19491955
struct commit *head =
19501956
lookup_commit_reference(the_repository,
19511957
&options.orig_head);

t/t3431-rebase-fork-point.sh

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,23 @@ test_expect_success setup '
2929
test_commit G
3030
'
3131

32+
do_test_rebase () {
33+
expected="$1" &&
34+
shift &&
35+
git checkout main &&
36+
git reset --hard E &&
37+
git checkout side &&
38+
git reset --hard G &&
39+
git rebase $* &&
40+
test_write_lines $expected >expect &&
41+
git log --pretty=%s >actual &&
42+
test_cmp expect actual
43+
}
44+
3245
test_rebase () {
3346
expected="$1" &&
3447
shift &&
35-
test_expect_success "git rebase $*" "
36-
git checkout main &&
37-
git reset --hard E &&
38-
git checkout side &&
39-
git reset --hard G &&
40-
git rebase $* &&
41-
test_write_lines $expected >expect &&
42-
git log --pretty=%s >actual &&
43-
test_cmp expect actual
44-
"
48+
test_expect_success "git rebase $*" "do_test_rebase '$expected' $*"
4549
}
4650

4751
test_rebase 'G F E D B A'
@@ -77,4 +81,35 @@ test_expect_success 'git rebase --fork-point with ambigous refname' '
7781
test_must_fail git rebase --fork-point --onto D one
7882
'
7983

84+
test_expect_success '--fork-point and --root both given' '
85+
test_must_fail git rebase --fork-point --root 2>err &&
86+
test_i18ngrep "cannot combine" err
87+
'
88+
89+
test_expect_success 'rebase.forkPoint set to false' '
90+
test_config rebase.forkPoint false &&
91+
do_test_rebase "G F C E D B A"
92+
'
93+
94+
test_expect_success 'rebase.forkPoint set to false and then to true' '
95+
test_config_global rebase.forkPoint false &&
96+
test_config rebase.forkPoint true &&
97+
do_test_rebase "G F E D B A"
98+
'
99+
100+
test_expect_success 'rebase.forkPoint set to false and command line says --fork-point' '
101+
test_config rebase.forkPoint false &&
102+
do_test_rebase "G F E D B A" --fork-point
103+
'
104+
105+
test_expect_success 'rebase.forkPoint set to true and command line says --no-fork-point' '
106+
test_config rebase.forkPoint true &&
107+
do_test_rebase "G F C E D B A" --no-fork-point
108+
'
109+
110+
test_expect_success 'rebase.forkPoint set to true and --root given' '
111+
test_config rebase.forkPoint true &&
112+
git rebase --root
113+
'
114+
80115
test_done

0 commit comments

Comments
 (0)