git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] builtin-merge: give a proper error message for invalid strategies in config
@ 2008-07-21 16:10 Miklos Vajna
  2008-07-22  5:01 ` Junio C Hamano
  0 siblings, 1 reply; 71+ messages in thread
From: Miklos Vajna @ 2008-07-21 16:10 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

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@frugalware.org>
---
 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

^ permalink raw reply related	[flat|nested] 71+ messages in thread
* [PATCH 0/7] Allow custom merge strategies
@ 2008-07-26 11:54 Miklos Vajna
  2008-07-26 11:54 ` [PATCH 1/7] Make is_git_command() usable outside builtin-help Miklos Vajna
  2008-07-28  1:21 ` [PATCH 0/6] Allow custom merge strategies, take 2 Miklos Vajna
  0 siblings, 2 replies; 71+ messages in thread
From: Miklos Vajna @ 2008-07-26 11:54 UTC (permalink / raw)
  To: git

Hi,

This series adds support for custom merge strategies.

The first 3 patches modify builtin-help to allow using it from other
builtins. This is necessary because in the error message of 'git merge
-s foobar' we show something like 'git help -a', but we list only merge
strategies. A command is considered a merge strategy if it has a
git-merge- prefix and is listed in the all_strategy array or it is
somewhere in PATH, but outside `git --exec-path`, so that git-merge-ours
and other strategies are shown, git-merge-index and other
git-merge-named (but not strategy) commands are hidden.

The last two is about removing those problematic 'git-merge-index',
'git-merge-tree' and other bogus commands from the output of 'git merge
-s foobar'. I think the benefit of doing it that way is that we don't
have to maintain a list of commands which are named git-merge-foo but
not strategies _and_ the custom strategies can have a form of
git-merge-foo, without adding extra complexity (like forcing users to
name them git-merge-custom-foo).

NOTE: At the moment the custom strategies are named as git-merge-foo as
well, mainly because I think it's not that problematic to exclude the
already existing git-merge-fo non-strategy commands, but this can be
changed to git-merge-strategy-foo if we really want so.

Also, I'm aware that this is a feature and we are in rc freeze, I just
did not want to keep back this series till 1.6.0 is out.

Miklos Vajna (7):
  Make is_git_command() usable outside builtin-help
  builtin-help: change the current directory back in
    list_commands_in_dir()
  builtin-help: make list_commands() a bit more generic
  builtin-merge: allow using a custom strategy
  Add a new test for using a custom merge strategy
  builtin-help: make it possible to exclude some commands in
    list_commands()
  builtin-merge: avoid non-strategy git-merge commands in error message

 Makefile                |    1 +
 builtin-merge.c         |   30 +++++++++++++++++++++------
 help.c                  |   50 ++++++++++++++++++++++++----------------------
 help.h                  |   19 +++++++++++++++++
 t/t7606-merge-custom.sh |   45 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 114 insertions(+), 31 deletions(-)
 create mode 100644 help.h
 create mode 100755 t/t7606-merge-custom.sh

^ permalink raw reply	[flat|nested] 71+ messages in thread

end of thread, other threads:[~2008-07-30 17:28 UTC | newest]

Thread overview: 71+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-21 16:10 [PATCH] builtin-merge: give a proper error message for invalid strategies in config Miklos Vajna
2008-07-22  5:01 ` Junio C Hamano
2008-07-22  5:22   ` Junio C Hamano
2008-07-22  7:39   ` Miklos Vajna
2008-07-22  8:24     ` Junio C Hamano
2008-07-22 17:05       ` [PATCH] t7601: extend the 'merge picks up the best result' test Miklos Vajna
2008-07-26 11:54       ` Miklos Vajna
2008-07-26 11:54         ` [PATCH 2/7] builtin-help: change the current directory back in list_commands_in_dir() Miklos Vajna
2008-07-26 11:54           ` [PATCH 3/7] builtin-help: make list_commands() a bit more generic Miklos Vajna
2008-07-26 11:54             ` [PATCH 4/7] builtin-merge: allow using a custom strategy Miklos Vajna
2008-07-26 11:54               ` [PATCH 5/7] Add a new test for using a custom merge strategy Miklos Vajna
2008-07-26 11:54                 ` [PATCH 6/7] builtin-help: make it possible to exclude some commands in list_commands() Miklos Vajna
2008-07-26 11:54                   ` [PATCH 7/7] builtin-merge: avoid non-strategy git-merge commands in error message Miklos Vajna
2008-07-26 15:08                     ` Johannes Schindelin
2008-07-26 15:25                       ` Miklos Vajna
2008-07-26 15:27                         ` Miklos Vajna
2008-07-26 15:38                         ` Johannes Schindelin
2008-07-26 16:00                           ` Miklos Vajna
2008-07-26 17:01                             ` Johannes Schindelin
2008-07-26 17:12                               ` [PATCH] " Miklos Vajna
2008-07-26 18:28             ` [PATCH 3/7] builtin-help: make list_commands() a bit more generic Jonathan Nieder
2008-07-26 21:40               ` Miklos Vajna
2008-07-26 14:58           ` [PATCH 2/7] builtin-help: change the current directory back in list_commands_in_dir() Johannes Schindelin
2008-07-27 20:02           ` Junio C Hamano
2008-07-27 20:21             ` Johannes Schindelin
2008-07-27 20:34               ` [PATCH] Avoid chdir() " Johannes Schindelin
2008-07-26 12:33         ` [PATCH] t7601: extend the 'merge picks up the best result' test Miklos Vajna
  -- strict thread matches above, loose matches on Subject: below --
2008-07-26 11:54 [PATCH 0/7] Allow custom merge strategies Miklos Vajna
2008-07-26 11:54 ` [PATCH 1/7] Make is_git_command() usable outside builtin-help Miklos Vajna
2008-07-26 18:12   ` Jonathan Nieder
2008-07-28  1:18     ` Miklos Vajna
2008-07-28  1:21 ` [PATCH 0/6] Allow custom merge strategies, take 2 Miklos Vajna
2008-07-28  1:21   ` [PATCH 1/6] builtin-help: make is_git_command() usable outside builtin-help Miklos Vajna
2008-07-28  1:21     ` [PATCH 2/6] builtin-help: make list_commands() a bit more generic Miklos Vajna
2008-07-28  1:21       ` [PATCH 3/6] builtin-help: make it possible to exclude some commands in list_commands() Miklos Vajna
2008-07-28  1:21         ` [PATCH 4/6] builtin-merge: allow using a custom strategy Miklos Vajna
2008-07-28  1:21           ` [PATCH 5/6] builtin-merge: avoid non-strategy git-merge commands in error message Miklos Vajna
2008-07-28  1:21             ` [PATCH 6/6] Add a new test for using a custom merge strategy Miklos Vajna
2008-07-28 13:12               ` Johannes Schindelin
2008-07-28 23:39                 ` Miklos Vajna
2008-07-28 23:54                   ` Johannes Schindelin
2008-07-28 23:58                     ` Miklos Vajna
2008-07-29  0:01                       ` Miklos Vajna
2008-07-28 13:06             ` [PATCH 5/6] builtin-merge: avoid non-strategy git-merge commands in error message Johannes Schindelin
2008-07-28 23:48               ` [PATCH] builtin-merge: allow using a custom strategy Miklos Vajna
2008-07-28 23:59                 ` Johannes Schindelin
2008-07-28  1:36         ` [PATCH 3/6] builtin-help: make it possible to exclude some commands in list_commands() Junio C Hamano
2008-07-28  2:43           ` Johannes Schindelin
2008-07-28  3:05             ` Junio C Hamano
2008-07-28  4:29               ` Junio C Hamano
2008-07-28  9:58               ` Johannes Schindelin
2008-07-28 23:24           ` Miklos Vajna
2008-07-29 15:24   ` [PATCH 0/5] Allow custom merge strategies, take 3 Miklos Vajna
2008-07-29 15:24     ` [PATCH 1/5] builtin-help: make is_git_command() usable outside builtin-help Miklos Vajna
2008-07-29 15:25       ` [PATCH 2/5] builtin-help: make list_commands() a bit more generic Miklos Vajna
2008-07-29 15:25         ` [PATCH 3/5] builtin-help: make it possible to exclude some commands in list_commands() Miklos Vajna
2008-07-29 15:25           ` [PATCH 4/5] builtin-merge: allow using a custom strategy Miklos Vajna
2008-07-29 15:25             ` [PATCH 5/5] Add a new test for using a custom merge strategy Miklos Vajna
2008-07-29 19:47             ` [PATCH 4/5] builtin-merge: allow using a custom strategy Junio C Hamano
2008-07-29 23:16               ` [PATCH 0/4] Allow custom merge strategies, take 4 Miklos Vajna
2008-07-29 23:16                 ` [PATCH 1/4] builtin-help: make some internal functions available to other builtins Miklos Vajna
2008-07-29 23:16                   ` [PATCH 2/4] builtin-merge: allow using a custom strategy Miklos Vajna
2008-07-29 23:17                     ` [PATCH 3/4] Add a new test for using a custom merge strategy Miklos Vajna
2008-07-29 23:17                       ` [PATCH 4/4] Add a second testcase for handling invalid strategies in git-merge Miklos Vajna
2008-07-29 23:42                         ` Junio C Hamano
2008-07-30 17:27                           ` Miklos Vajna
2008-07-29 23:43                       ` [PATCH 3/4] Add a new test for using a custom merge strategy Junio C Hamano
2008-07-30 17:25                         ` Miklos Vajna
2008-07-30  6:21                   ` [PATCH 1/4] builtin-help: make some internal functions available to other builtins Junio C Hamano
2008-07-29 19:46           ` [PATCH 3/5] builtin-help: make it possible to exclude some commands in list_commands() Junio C Hamano
2008-07-29 21:25             ` Miklos Vajna

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).