[PATCH] builtin-merge: give a proper error message for invalid strategies in config

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Till now 'git merge -s foobar' bailed out with an error message, but
foobar in pull.twohead or pull.octopus was just silently ignored. It's
better to inform the user then just silently doing nothing.

Signed-off-by: Miklos Vajna <vmiklos@xxxxxxxxxxxxxx>
---
 builtin-merge.c              |   35 +++++++++++++++--------------------
 t/t7601-merge-pull-config.sh |    6 ++++++
 2 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/builtin-merge.c b/builtin-merge.c
index e97c79e..5037acf 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -93,28 +93,13 @@ static void append_strategy(struct strategy *s)
 	use_strategies[use_strategies_nr++] = s;
 }
 
+static void add_strategies(const char *string, unsigned attr);
+
 static int option_parse_strategy(const struct option *opt,
 				 const char *name, int unset)
 {
-	int i;
-	struct strategy *s;
-
-	if (unset)
-		return 0;
-
-	s = get_strategy(name);
-
-	if (s)
-		append_strategy(s);
-	else {
-		struct strbuf err;
-		strbuf_init(&err, 0);
-		for (i = 0; i < ARRAY_SIZE(all_strategy); i++)
-			strbuf_addf(&err, " %s", all_strategy[i].name);
-		fprintf(stderr, "Could not find merge strategy '%s'.\n", name);
-		fprintf(stderr, "Available strategies are:%s.\n", err.buf);
-		exit(1);
-	}
+	if (!unset)
+		add_strategies(name, 0);
 	return 0;
 }
 
@@ -639,7 +624,7 @@ static void split_merge_strategies(const char *string, struct strategy **list,
 static void add_strategies(const char *string, unsigned attr)
 {
 	struct strategy *list = NULL;
-	int list_alloc = 0, list_nr = 0, i;
+	int list_alloc = 0, list_nr = 0, i, j;
 
 	memset(&list, 0, sizeof(list));
 	split_merge_strategies(string, &list, &list_nr, &list_alloc);
@@ -650,6 +635,16 @@ static void add_strategies(const char *string, unsigned attr)
 			s = get_strategy(list[i].name);
 			if (s)
 				append_strategy(s);
+			else {
+				struct strbuf err;
+
+				strbuf_init(&err, 0);
+				for (j = 0; j < ARRAY_SIZE(all_strategy); j++)
+					strbuf_addf(&err, " %s", all_strategy[j].name);
+				fprintf(stderr, "Could not find merge strategy '%s'.\n", list[i].name);
+				fprintf(stderr, "Available strategies are:%s.\n", err.buf);
+				exit(1);
+			}
 		}
 		return;
 	}
diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh
index 95b4d71..ca63451 100755
--- a/t/t7601-merge-pull-config.sh
+++ b/t/t7601-merge-pull-config.sh
@@ -126,4 +126,10 @@ test_expect_success 'merge picks up the best result' '
 	test $auto_count != $resolve_count
 '
 
+test_expect_success 'merge errors out on invalid strategy' '
+	git config pull.twohead "foobar" &&
+	git reset --hard c5 &&
+	test_must_fail git merge c6
+'
+
 test_done
-- 
1.5.6.4.433.g09651.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux