git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] submodule--helper: offer a consistent API

From
Stefan Beller <sbeller@google.com>
Date
May 31, 2016, 23:59 UTC
Message-ID
<20160531235933.3854-1-sbeller@google.com>

In 48308681 (2016-02-29, git submodule update: have a dedicated helper for cloning), the helper communicated errors back only via exit code, and dance with printing '#unmatched' in case of error was left to git-submodule.sh as it uses the output of the helper and pipes it into shell commands. This change makes the helper consistent by never printing '#unmatched' in the helper but always handling these piping issues in the actual shell script.

Signed-off-by: Stefan Beller <sbeller@google.com>
---

I think this applies on any of the recent submodule branches; certainly on master (Git 2.9-rc1).

Thanks, Stefan

 builtin/submodule--helper.c |  4 +---
 git-submodule.sh            | 20 ++++++++++++++++----
 2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index ca33408..b1ebee2 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -287,10 +287,8 @@ static int module_list(int argc, const char **argv, const char *prefix)
 	argc = parse_options(argc, argv, prefix, module_list_options,
 			     git_submodule_helper_usage, 0);
 
-	if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) {
-		printf("#unmatched\n");
+	if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0)
 		return 1;
-	}
 
 	for (i = 0; i < list.nr; i++) {
 		const struct cache_entry *ce = list.entries[i];
diff --git a/git-submodule.sh b/git-submodule.sh
index 42e0e9f..0515019 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -345,7 +345,10 @@ cmd_foreach()
 	# command in the subshell (and a recursive call to this function)
 	exec 3<&0
 
-	git submodule--helper list --prefix "$wt_prefix"|
+	{
+		git submodule--helper list --prefix "$wt_prefix" ||
+		echo "#unmatched"
+	} |
 	while read mode sha1 stage sm_path
 	do
 		die_if_unmatched "$mode"
@@ -453,7 +456,10 @@ cmd_deinit()
 		die "$(eval_gettext "Use '--all' if you really want to deinitialize all submodules")"
 	fi
 
-	git submodule--helper list --prefix "$wt_prefix" "$@" |
+	{
+		git submodule--helper list --prefix "$wt_prefix" "$@" ||
+		echo "#unmatched"
+	} |
 	while read mode sha1 stage sm_path
 	do
 		die_if_unmatched "$mode"
@@ -1020,7 +1026,10 @@ cmd_status()
 		shift
 	done
 
-	git submodule--helper list --prefix "$wt_prefix" "$@" |
+	{
+		git submodule--helper list --prefix "$wt_prefix" "$@" ||
+		echo "#unmatched"
+	} |
 	while read mode sha1 stage sm_path
 	do
 		die_if_unmatched "$mode"
@@ -1098,7 +1107,10 @@ cmd_sync()
 		esac
 	done
 	cd_to_toplevel
-	git submodule--helper list --prefix "$wt_prefix" "$@" |
+	{
+		git submodule--helper list --prefix "$wt_prefix" "$@" ||
+		echo "#unmatched"
+	} |
 	while read mode sha1 stage sm_path
 	do
 		die_if_unmatched "$mode"
-- 
2.9.0.rc0.2.g145fc64
Message 1 of 1 in “submodule--helper: offer a consistent API”
  1. submodule--helper: offer a consistent APIStefan Beller, May 31, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.