Skip to content

Commit 2803d80

Browse files
alexhenriegitster
authored andcommitted
rebase: add a config option for --no-fork-point
Some users (myself included) would prefer to have this feature off by default because it can silently drop commits. Signed-off-by: Alex Henrie <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 66e871b commit 2803d80

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
@@ -26,19 +26,23 @@ test_expect_success setup '
2626
test_commit G
2727
'
2828

29+
do_test_rebase () {
30+
expected="$1" &&
31+
shift &&
32+
git checkout master &&
33+
git reset --hard E &&
34+
git checkout side &&
35+
git reset --hard G &&
36+
git rebase $* &&
37+
test_write_lines $expected >expect &&
38+
git log --pretty=%s >actual &&
39+
test_cmp expect actual
40+
}
41+
2942
test_rebase () {
3043
expected="$1" &&
3144
shift &&
32-
test_expect_success "git rebase $*" "
33-
git checkout master &&
34-
git reset --hard E &&
35-
git checkout side &&
36-
git reset --hard G &&
37-
git rebase $* &&
38-
test_write_lines $expected >expect &&
39-
git log --pretty=%s >actual &&
40-
test_cmp expect actual
41-
"
45+
test_expect_success "git rebase $*" "do_test_rebase '$expected' $*"
4246
}
4347

4448
test_rebase 'G F E D B A'
@@ -74,4 +78,35 @@ test_expect_success 'git rebase --fork-point with ambigous refname' '
7478
test_must_fail git rebase --fork-point --onto D one
7579
'
7680

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

0 commit comments

Comments
 (0)