Skip to content

Commit eddfcd8

Browse files
newrengitster
authored andcommitted
rebase: provide better error message for apply options vs. merge config
When config which selects the merge backend (currently, rebase.autosquash=true or rebase.updateRefs=true) conflicts with other options on the command line (such as --whitespace=fix), make the error message specifically call out the config option and specify how to override that config option on the command line. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3dc55b2 commit eddfcd8

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

Documentation/git-rebase.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ are incompatible with the following options:
648648
* --merge
649649
* --strategy
650650
* --strategy-option
651-
* --[no-]autosquash
651+
* --autosquash
652652
* --rebase-merges
653653
* --interactive
654654
* --exec

builtin/rebase.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ struct rebase_options {
122122
int reapply_cherry_picks;
123123
int fork_point;
124124
int update_refs;
125+
int config_autosquash;
126+
int config_update_refs;
125127
};
126128

127129
#define REBASE_OPTIONS_INIT { \
@@ -136,6 +138,10 @@ struct rebase_options {
136138
.fork_point = -1, \
137139
.reapply_cherry_picks = -1, \
138140
.allow_empty_message = 1, \
141+
.autosquash = -1, \
142+
.config_autosquash = -1, \
143+
.update_refs = -1, \
144+
.config_update_refs = -1, \
139145
}
140146

141147
static struct replay_opts get_replay_opts(const struct rebase_options *opts)
@@ -778,7 +784,7 @@ static int rebase_config(const char *var, const char *value, void *data)
778784
}
779785

780786
if (!strcmp(var, "rebase.autosquash")) {
781-
opts->autosquash = git_config_bool(var, value);
787+
opts->config_autosquash = git_config_bool(var, value);
782788
return 0;
783789
}
784790

@@ -795,7 +801,7 @@ static int rebase_config(const char *var, const char *value, void *data)
795801
}
796802

797803
if (!strcmp(var, "rebase.updaterefs")) {
798-
opts->update_refs = git_config_bool(var, value);
804+
opts->config_update_refs = git_config_bool(var, value);
799805
return 0;
800806
}
801807

@@ -1366,7 +1372,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
13661372
if ((options.flags & REBASE_INTERACTIVE_EXPLICIT) ||
13671373
(options.action != ACTION_NONE) ||
13681374
(options.exec.nr > 0) ||
1369-
options.autosquash) {
1375+
(options.autosquash == -1 && options.config_autosquash == 1) ||
1376+
options.autosquash == 1) {
13701377
allow_preemptive_ff = 0;
13711378
}
13721379
if (options.committer_date_is_author_date || options.ignore_date)
@@ -1499,20 +1506,28 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
14991506
if (strcmp(options.git_am_opts.v[i], "-q"))
15001507
break;
15011508

1502-
if (i >= 0) {
1509+
if (i >= 0 || options.type == REBASE_APPLY) {
15031510
if (is_merge(&options))
15041511
die(_("apply options and merge options "
15051512
"cannot be used together"));
1513+
else if (options.autosquash == -1 && options.config_autosquash == 1)
1514+
die(_("apply options are incompatible with rebase.autosquash. Consider adding --no-autosquash"));
1515+
else if (options.update_refs == -1 && options.config_update_refs == 1)
1516+
die(_("apply options are incompatible with rebase.updateRefs. Consider adding --no-update-refs"));
15061517
else
15071518
options.type = REBASE_APPLY;
15081519
}
15091520
}
15101521

1511-
if (options.update_refs)
1522+
if (options.update_refs == 1)
15121523
imply_merge(&options, "--update-refs");
1524+
options.update_refs = (options.update_refs >= 0) ? options.update_refs :
1525+
((options.config_update_refs >= 0) ? options.config_update_refs : 0);
15131526

1514-
if (options.autosquash)
1527+
if (options.autosquash == 1)
15151528
imply_merge(&options, "--autosquash");
1529+
options.autosquash = (options.autosquash >= 0) ? options.autosquash :
1530+
((options.config_autosquash >= 0) ? options.config_autosquash : 0);
15161531

15171532
if (options.type == REBASE_UNSPECIFIED) {
15181533
if (!strcmp(options.default_backend, "merge"))

t/t3422-rebase-incompatible-options.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,30 @@ test_rebase_am_only () {
9494
git checkout B^0 &&
9595
test_must_fail git rebase $opt --root A
9696
"
97+
98+
test_expect_success "$opt incompatible with rebase.autosquash" "
99+
git checkout B^0 &&
100+
test_must_fail git -c rebase.autosquash=true rebase $opt A 2>err &&
101+
grep -e --no-autosquash err
102+
"
103+
104+
test_expect_success "$opt incompatible with rebase.updateRefs" "
105+
git checkout B^0 &&
106+
test_must_fail git -c rebase.updateRefs=true rebase $opt A 2>err &&
107+
grep -e --no-update-refs err
108+
"
109+
110+
test_expect_success "$opt okay with overridden rebase.autosquash" "
111+
test_when_finished \"git reset --hard B^0\" &&
112+
git checkout B^0 &&
113+
git -c rebase.autosquash=true rebase --no-autosquash $opt A
114+
"
115+
116+
test_expect_success "$opt okay with overridden rebase.updateRefs" "
117+
test_when_finished \"git reset --hard B^0\" &&
118+
git checkout B^0 &&
119+
git -c rebase.updateRefs=true rebase --no-update-refs $opt A
120+
"
97121
}
98122

99123
# Check options which imply --apply

0 commit comments

Comments
 (0)