builtin-merge: give a proper error message for invalid strategies in config
'git merge -s foobar' diagnosed invalid "foobar" strategy and errored out with a message, but foobar in pull.twohead or pull.octopus was just silently ignored. This makes invalid strategy both on the command line and in the configuration file to trigger the same error. Signed-off-by: Miklos Vajna <vmiklos@frugalware.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Miklos Vajna committed
Jul 21, 2008 at 18:10 UTC
1719b5e446f54e4196903ae6ed5f8867a5755bf6
2 files changed
+24
-25
builtin-merge.c
+12
-25
@@ -77,6 +77,7 @@ static int option_parse_message(const struct option *opt,
77
static struct strategy *get_strategy(const char *name)
78
{
79
int i;
80
+ struct strbuf err;
81
82
if (!name)
83
return NULL;
@@ -84,7 +85,13 @@ static struct strategy *get_strategy(const char *name)
85
for (i = 0; i < ARRAY_SIZE(all_strategy); i++)
86
if (!strcmp(name, all_strategy[i].name))
87
return &all_strategy[i];
87
- return NULL;
88
+
89
+ strbuf_init(&err, 0);
90
+ for (i = 0; i < ARRAY_SIZE(all_strategy); i++)
91
+ strbuf_addf(&err, " %s", all_strategy[i].name);
92
+ fprintf(stderr, "Could not find merge strategy '%s'.\n", name);
93
+ fprintf(stderr, "Available strategies are:%s.\n", err.buf);
94
+ exit(1);
95
}
96
97
static void append_strategy(struct strategy *s)
@@ -96,25 +103,10 @@ static void append_strategy(struct strategy *s)
103
static int option_parse_strategy(const struct option *opt,
104
const char *name, int unset)
105
{
99
- int i;
100
- struct strategy *s;
101
-
106
if (unset)
107
return 0;
108
105
- s = get_strategy(name);
106
-
107
- if (s)
108
- append_strategy(s);
109
- else {
110
- struct strbuf err;
111
- strbuf_init(&err, 0);
112
- for (i = 0; i < ARRAY_SIZE(all_strategy); i++)
113
- strbuf_addf(&err, " %s", all_strategy[i].name);
114
- fprintf(stderr, "Could not find merge strategy '%s'.\n", name);
115
- fprintf(stderr, "Available strategies are:%s.\n", err.buf);
116
- exit(1);
117
- }
109
+ append_strategy(get_strategy(name));
110
return 0;
111
}
112
@@ -643,14 +635,9 @@ static void add_strategies(const char *string, unsigned attr)
635
636
memset(&list, 0, sizeof(list));
637
split_merge_strategies(string, &list, &list_nr, &list_alloc);
646
- if (list != NULL) {
647
- for (i = 0; i < list_nr; i++) {
648
- struct strategy *s;
649
-
650
- s = get_strategy(list[i].name);
651
- if (s)
652
- append_strategy(s);
653
- }
638
+ if (list) {
639
+ for (i = 0; i < list_nr; i++)
640
+ append_strategy(get_strategy(list[i].name));
641
return;
642
}
643
for (i = 0; i < ARRAY_SIZE(all_strategy); i++)
t/t7601-merge-pull-config.sh
+12
@@ -126,4 +126,16 @@ test_expect_success 'merge picks up the best result' '
126
test $auto_count != $resolve_count
127
'
128
129
+test_expect_success 'merge errors out on invalid strategy' '
130
+ git config pull.twohead "foobar" &&
131
+ git reset --hard c5 &&
132
+ test_must_fail git merge c6
133
+'
134
+
135
+test_expect_success 'merge errors out on invalid strategy' '
136
+ git config --unset-all pull.twohead &&
137
+ git reset --hard c5 &&
138
+ test_must_fail git merge -s "resolve recursive" c6
139
+'
140
+
141
test_done