git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 0/3] pass credential.* to submodules
@ 2016-02-27  0:13 Jacob Keller
  2016-02-27  0:13 ` [PATCH v5 1/3] sumodule--helper: fix submodule--helper clone usage and check argc count Jacob Keller
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Jacob Keller @ 2016-02-27  0:13 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Mark Strapetz, Stefan Beller, Junio C Hamano,
	Jacob Keller

From: Jacob Keller <jacob.keller@gmail.com>

This version of the series fixes up a few issues and implements
sq_quotef function to help make intent more clear in the code. I also
chose to use Jeff's implementation for the test fix since I think it
works better and I prefer the consistency of implementation.

Interdiff between v4 and v5:

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index c6c0a3b06e27..43943eef81b4 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -147,16 +147,7 @@ static int sanitize_submodule_config(const char *var, const char *value, void *d
 		if (out->len)
 			strbuf_addch(out, ' ');
 
-		/*
-		 * The GIT_CONFIG_PARAMETERS parser is a bit picky and
-		 * requires that each var=value pair be quoted as a single
-		 * unit.
-		 */
-		strbuf_addstr(&quoted, var);
-		strbuf_addch(&quoted, '=');
-		strbuf_addstr(&quoted, value);
-
-		sq_quote_buf(out, quoted.buf);
+		sq_quotef(out, "%s=%s", var, value);
 	}
 
 	strbuf_release(&quoted);
diff --git a/quote.c b/quote.c
index fe884d24521f..b281a8fe454e 100644
--- a/quote.c
+++ b/quote.c
@@ -43,6 +43,19 @@ void sq_quote_buf(struct strbuf *dst, const char *src)
 	free(to_free);
 }
 
+void sq_quotef(struct strbuf *dst, const char *fmt, ...)
+{
+	struct strbuf src = STRBUF_INIT;
+
+	va_list ap;
+	va_start(ap, fmt);
+	strbuf_vaddf(&src, fmt, ap);
+	va_end(ap);
+
+	sq_quote_buf(dst, src.buf);
+	strbuf_release(&src);
+}
+
 void sq_quote_argv(struct strbuf *dst, const char** argv, size_t maxlen)
 {
 	int i;
diff --git a/quote.h b/quote.h
index 99e04d34bf22..6c53a2cc66c4 100644
--- a/quote.h
+++ b/quote.h
@@ -25,10 +25,13 @@ struct strbuf;
  * sq_quote_buf() writes to an existing buffer of specified size; it
  * will return the number of characters that would have been written
  * excluding the final null regardless of the buffer size.
+ *
+ * sq_quotef() quotes the entire formatted string as a single result.
  */
 
 extern void sq_quote_buf(struct strbuf *, const char *src);
 extern void sq_quote_argv(struct strbuf *, const char **argv, size_t maxlen);
+extern void sq_quotef(struct strbuf *, const char *fmt, ...);
 
 /* This unwraps what sq_quote() produces in place, but returns
  * NULL if the input does not look like what sq_quote would have
diff --git a/t/t7412-submodule--helper.sh b/t/t7412-submodule--helper.sh
index 9d937de8b224..149d42864f29 100755
--- a/t/t7412-submodule--helper.sh
+++ b/t/t7412-submodule--helper.sh
@@ -16,12 +16,11 @@ test_expect_success 'sanitize-config clears configuration' '
 	test_must_be_empty actual
 '
 
-test_expect_success 'sanitize-config keeps credential.helper' "
+sq="'"
+test_expect_success 'sanitize-config keeps credential.helper' '
 	git -c credential.helper=helper submodule--helper sanitize-config >actual &&
-	cat >expect <<-EOF &&
-	'credential.helper=helper'
-	EOF
+	echo "${sq}credential.helper=helper${sq}" >expect &&
 	test_cmp expect actual
-"
+'
 
 test_done

Jacob Keller (3):
  sumodule--helper: fix submodule--helper clone usage and check argc
    count
  quote: implement sq_quotef()
  git: submodule honor -c credential.* from command line

 builtin/submodule--helper.c  | 73 ++++++++++++++++++++++++++++++++++++++++++--
 git-submodule.sh             | 40 +++++++++++++++---------
 quote.c                      | 13 ++++++++
 quote.h                      |  3 ++
 t/t5550-http-fetch-dumb.sh   | 17 +++++++++++
 t/t7412-submodule--helper.sh | 26 ++++++++++++++++
 6 files changed, 155 insertions(+), 17 deletions(-)
 create mode 100755 t/t7412-submodule--helper.sh

-- 
2.7.1.429.g45cd78e

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

* [PATCH v5 1/3] sumodule--helper: fix submodule--helper clone usage and check argc count
  2016-02-27  0:13 [PATCH v5 0/3] pass credential.* to submodules Jacob Keller
@ 2016-02-27  0:13 ` Jacob Keller
  2016-02-29 17:49   ` Junio C Hamano
  2016-02-27  0:13 ` [PATCH v5 2/3] quote: implement sq_quotef() Jacob Keller
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 13+ messages in thread
From: Jacob Keller @ 2016-02-27  0:13 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Mark Strapetz, Stefan Beller, Junio C Hamano,
	Jacob Keller

From: Jacob Keller <jacob.keller@gmail.com>

git submodule--helper clone usage specified that paths come after the --
as a sequence. However, the actual implementation does not, and requires
only a single path passed in via --path. In addition, argc was
unchecked. (allowing arbitrary extra arguments that were silently
ignored).

Fix the usage description to match implementation. Add an argc check to
enforce no extra arguments. Fix a bug in the argument passing in
git-submodule.sh which would pass --reference and --depth as empty
strings when they were unused, resulting in extra argc after parsing
options.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
---
 builtin/submodule--helper.c | 5 ++++-
 git-submodule.sh            | 4 ++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index f4c3eff179b5..072d9bbd12a8 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -187,13 +187,16 @@ static int module_clone(int argc, const char **argv, const char *prefix)
 	const char *const git_submodule_helper_usage[] = {
 		N_("git submodule--helper clone [--prefix=<path>] [--quiet] "
 		   "[--reference <repository>] [--name <name>] [--url <url>]"
-		   "[--depth <depth>] [--] [<path>...]"),
+		   "[--depth <depth>] [--path <path>]"),
 		NULL
 	};
 
 	argc = parse_options(argc, argv, prefix, module_clone_options,
 			     git_submodule_helper_usage, 0);
 
+	if (argc)
+		usage(*git_submodule_helper_usage);
+
 	strbuf_addf(&sb, "%s/modules/%s", get_git_dir(), name);
 	sm_gitdir = strbuf_detach(&sb, NULL);
 
diff --git a/git-submodule.sh b/git-submodule.sh
index 9bc5c5f94d1d..2dd29b3df0e6 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -347,7 +347,7 @@ Use -f if you really want to add it." >&2
 				echo "$(eval_gettext "Reactivating local git directory for submodule '\$sm_name'.")"
 			fi
 		fi
-		git submodule--helper clone ${GIT_QUIET:+--quiet} --prefix "$wt_prefix" --path "$sm_path" --name "$sm_name" --url "$realrepo" "$reference" "$depth" || exit
+		git submodule--helper clone ${GIT_QUIET:+--quiet} --prefix "$wt_prefix" --path "$sm_path" --name "$sm_name" --url "$realrepo" ${reference:+"$reference"} ${depth:+"$depth"} || exit
 		(
 			clear_local_git_env
 			cd "$sm_path" &&
@@ -709,7 +709,7 @@ Maybe you want to use 'update --init'?")"
 
 		if ! test -d "$sm_path"/.git && ! test -f "$sm_path"/.git
 		then
-			git submodule--helper clone ${GIT_QUIET:+--quiet} --prefix "$prefix" --path "$sm_path" --name "$name" --url "$url" "$reference" "$depth" || exit
+			git submodule--helper clone ${GIT_QUIET:+--quiet} --prefix "$prefix" --path "$sm_path" --name "$name" --url "$url" ${reference:+"$reference"} ${depth:+"$depth"} || exit
 			cloned_modules="$cloned_modules;$name"
 			subsha1=
 		else
-- 
2.7.1.429.g45cd78e

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

* [PATCH v5 2/3] quote: implement sq_quotef()
  2016-02-27  0:13 [PATCH v5 0/3] pass credential.* to submodules Jacob Keller
  2016-02-27  0:13 ` [PATCH v5 1/3] sumodule--helper: fix submodule--helper clone usage and check argc count Jacob Keller
@ 2016-02-27  0:13 ` Jacob Keller
  2016-02-27  0:13 ` [PATCH v5 3/3] git: submodule honor -c credential.* from command line Jacob Keller
  2016-02-27  0:37 ` [PATCH v5 0/3] pass credential.* to submodules Jacob Keller
  3 siblings, 0 replies; 13+ messages in thread
From: Jacob Keller @ 2016-02-27  0:13 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Mark Strapetz, Stefan Beller, Junio C Hamano,
	Jacob Keller

From: Jacob Keller <jacob.keller@gmail.com>

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
---
 quote.c | 13 +++++++++++++
 quote.h |  3 +++
 2 files changed, 16 insertions(+)

diff --git a/quote.c b/quote.c
index fe884d24521f..b281a8fe454e 100644
--- a/quote.c
+++ b/quote.c
@@ -43,6 +43,19 @@ void sq_quote_buf(struct strbuf *dst, const char *src)
 	free(to_free);
 }
 
+void sq_quotef(struct strbuf *dst, const char *fmt, ...)
+{
+	struct strbuf src = STRBUF_INIT;
+
+	va_list ap;
+	va_start(ap, fmt);
+	strbuf_vaddf(&src, fmt, ap);
+	va_end(ap);
+
+	sq_quote_buf(dst, src.buf);
+	strbuf_release(&src);
+}
+
 void sq_quote_argv(struct strbuf *dst, const char** argv, size_t maxlen)
 {
 	int i;
diff --git a/quote.h b/quote.h
index 99e04d34bf22..6c53a2cc66c4 100644
--- a/quote.h
+++ b/quote.h
@@ -25,10 +25,13 @@ struct strbuf;
  * sq_quote_buf() writes to an existing buffer of specified size; it
  * will return the number of characters that would have been written
  * excluding the final null regardless of the buffer size.
+ *
+ * sq_quotef() quotes the entire formatted string as a single result.
  */
 
 extern void sq_quote_buf(struct strbuf *, const char *src);
 extern void sq_quote_argv(struct strbuf *, const char **argv, size_t maxlen);
+extern void sq_quotef(struct strbuf *, const char *fmt, ...);
 
 /* This unwraps what sq_quote() produces in place, but returns
  * NULL if the input does not look like what sq_quote would have
-- 
2.7.1.429.g45cd78e

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

* [PATCH v5 3/3] git: submodule honor -c credential.* from command line
  2016-02-27  0:13 [PATCH v5 0/3] pass credential.* to submodules Jacob Keller
  2016-02-27  0:13 ` [PATCH v5 1/3] sumodule--helper: fix submodule--helper clone usage and check argc count Jacob Keller
  2016-02-27  0:13 ` [PATCH v5 2/3] quote: implement sq_quotef() Jacob Keller
@ 2016-02-27  0:13 ` Jacob Keller
  2016-02-29 18:20   ` Junio C Hamano
  2016-02-27  0:37 ` [PATCH v5 0/3] pass credential.* to submodules Jacob Keller
  3 siblings, 1 reply; 13+ messages in thread
From: Jacob Keller @ 2016-02-27  0:13 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Mark Strapetz, Stefan Beller, Junio C Hamano,
	Jacob Keller

From: Jacob Keller <jacob.keller@gmail.com>

Due to the way that the git-submodule code works, it clears all local
git environment variables before entering submodules. This is normally
a good thing since we want to clear settings such as GIT_WORKTREE and
other variables which would affect the operation of submodule commands.
However, GIT_CONFIG_PARAMETERS is special, and we actually do want to
preserve these settings. However, we do not want to preserve all
configuration as many things should be left specific to the parent
project.

Add a git submodule--helper function, sanitize-config, which shall be
used to sanitize GIT_CONFIG_PARAMETERS, removing all key/value pairs
except a small subset that are known to be safe and necessary.

Replace all the calls to clear_local_git_env with a wrapped function
that filters GIT_CONFIG_PARAMETERS using the new helper and then
restores it to the filtered subset after clearing the rest of the
environment.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
---

Notes:
    - v2
    * Clarify which paramaters are left after the sanitization, and don't seem to
      indicate it is our goal to extend the list.
    * add a comment in the submodule_config_ok function indicating the same
    
    - v3
    * Remove extraneous comments
    * add strbuf_release calls
    * rename sanitize_local_git_env
    * remove use of local
    * add C equivalent of sanitize_config
    * add a test for the credential passing
    
    - v4
    * use argc check instead of empty options check
    * fix brain-melting quotes in t7412-submodule--helper.sh
    
    - v5
    * use new sq_quote_f
    * fix test to use ${sq} style to prevent need of complex quotes or the use of
      double quotes on the test body

 builtin/submodule--helper.c  | 68 +++++++++++++++++++++++++++++++++++++++++++-
 git-submodule.sh             | 36 ++++++++++++++---------
 t/t5550-http-fetch-dumb.sh   | 17 +++++++++++
 t/t7412-submodule--helper.sh | 26 +++++++++++++++++
 4 files changed, 133 insertions(+), 14 deletions(-)
 create mode 100755 t/t7412-submodule--helper.sh

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 072d9bbd12a8..43943eef81b4 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -124,6 +124,55 @@ static int module_name(int argc, const char **argv, const char *prefix)
 
 	return 0;
 }
+
+/*
+ * Rules to sanitize configuration variables that are Ok to be passed into
+ * submodule operations from the parent project using "-c". Should only
+ * include keys which are both (a) safe and (b) necessary for proper
+ * operation.
+ */
+static int submodule_config_ok(const char *var)
+{
+	if (starts_with(var, "credential."))
+		return 1;
+	return 0;
+}
+
+static int sanitize_submodule_config(const char *var, const char *value, void *data)
+{
+	struct strbuf quoted = STRBUF_INIT;
+	struct strbuf *out = data;
+
+	if (submodule_config_ok(var)) {
+		if (out->len)
+			strbuf_addch(out, ' ');
+
+		sq_quotef(out, "%s=%s", var, value);
+	}
+
+	strbuf_release(&quoted);
+
+	return 0;
+}
+
+static void prepare_submodule_repo_env(struct argv_array *out)
+{
+	const char * const *var;
+
+	for (var = local_repo_env; *var; var++) {
+		if (!strcmp(*var, CONFIG_DATA_ENVIRONMENT)) {
+			struct strbuf sanitized_config = STRBUF_INIT;
+			git_config_from_parameters(sanitize_submodule_config,
+						   &sanitized_config);
+			argv_array_pushf(out, "%s=%s", *var, sanitized_config.buf);
+			strbuf_release(&sanitized_config);
+		} else {
+			argv_array_push(out, *var);
+		}
+	}
+
+}
+
 static int clone_submodule(const char *path, const char *gitdir, const char *url,
 			   const char *depth, const char *reference, int quiet)
 {
@@ -145,7 +194,7 @@ static int clone_submodule(const char *path, const char *gitdir, const char *url
 	argv_array_push(&cp.args, path);
 
 	cp.git_cmd = 1;
-	cp.env = local_repo_env;
+	prepare_submodule_repo_env(&cp.env_array);
 	cp.no_stdin = 1;
 
 	return run_command(&cp);
@@ -258,6 +307,22 @@ static int module_clone(int argc, const char **argv, const char *prefix)
 	return 0;
 }
 
+static int module_sanitize_config(int argc, const char **argv, const char *prefix)
+{
+	struct strbuf sanitized_config = STRBUF_INIT;
+
+	if (argc > 1)
+		usage(_("git submodule--helper sanitize-config"));
+
+	git_config_from_parameters(sanitize_submodule_config, &sanitized_config);
+	if (sanitized_config.len)
+		printf("%s\n", sanitized_config.buf);
+
+	strbuf_release(&sanitized_config);
+
+	return 0;
+}
+
 struct cmd_struct {
 	const char *cmd;
 	int (*fn)(int, const char **, const char *);
@@ -267,6 +332,7 @@ static struct cmd_struct commands[] = {
 	{"list", module_list},
 	{"name", module_name},
 	{"clone", module_clone},
+	{"sanitize-config", module_sanitize_config},
 };
 
 int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
diff --git a/git-submodule.sh b/git-submodule.sh
index 2dd29b3df0e6..1f132b489b81 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -192,6 +192,16 @@ isnumber()
 	n=$(($1 + 0)) 2>/dev/null && test "$n" = "$1"
 }
 
+# Sanitize the local git environment for use within a submodule. We
+# can't simply use clear_local_git_env since we want to preserve some
+# of the settings from GIT_CONFIG_PARAMETERS.
+sanitize_submodule_env()
+{
+	sanitized_config=$(git submodule--helper sanitize-config)
+	clear_local_git_env
+	GIT_CONFIG_PARAMETERS=$sanitized_config
+}
+
 #
 # Add a new submodule to the working tree, .gitmodules and the index
 #
@@ -349,7 +359,7 @@ Use -f if you really want to add it." >&2
 		fi
 		git submodule--helper clone ${GIT_QUIET:+--quiet} --prefix "$wt_prefix" --path "$sm_path" --name "$sm_name" --url "$realrepo" ${reference:+"$reference"} ${depth:+"$depth"} || exit
 		(
-			clear_local_git_env
+			sanitize_submodule_env
 			cd "$sm_path" &&
 			# ash fails to wordsplit ${branch:+-b "$branch"...}
 			case "$branch" in
@@ -418,7 +428,7 @@ cmd_foreach()
 			name=$(git submodule--helper name "$sm_path")
 			(
 				prefix="$prefix$sm_path/"
-				clear_local_git_env
+				sanitize_submodule_env
 				cd "$sm_path" &&
 				sm_path=$(relative_path "$sm_path") &&
 				# we make $path available to scripts ...
@@ -713,7 +723,7 @@ Maybe you want to use 'update --init'?")"
 			cloned_modules="$cloned_modules;$name"
 			subsha1=
 		else
-			subsha1=$(clear_local_git_env; cd "$sm_path" &&
+			subsha1=$(sanitize_submodule_env; cd "$sm_path" &&
 				git rev-parse --verify HEAD) ||
 			die "$(eval_gettext "Unable to find current revision in submodule path '\$displaypath'")"
 		fi
@@ -723,11 +733,11 @@ Maybe you want to use 'update --init'?")"
 			if test -z "$nofetch"
 			then
 				# Fetch remote before determining tracking $sha1
-				(clear_local_git_env; cd "$sm_path" && git-fetch) ||
+				(sanitize_submodule_env; cd "$sm_path" && git-fetch) ||
 				die "$(eval_gettext "Unable to fetch in submodule path '\$sm_path'")"
 			fi
-			remote_name=$(clear_local_git_env; cd "$sm_path" && get_default_remote)
-			sha1=$(clear_local_git_env; cd "$sm_path" &&
+			remote_name=$(sanitize_submodule_env; cd "$sm_path" && get_default_remote)
+			sha1=$(sanitize_submodule_env; cd "$sm_path" &&
 				git rev-parse --verify "${remote_name}/${branch}") ||
 			die "$(eval_gettext "Unable to find current ${remote_name}/${branch} revision in submodule path '\$sm_path'")"
 		fi
@@ -745,7 +755,7 @@ Maybe you want to use 'update --init'?")"
 			then
 				# Run fetch only if $sha1 isn't present or it
 				# is not reachable from a ref.
-				(clear_local_git_env; cd "$sm_path" &&
+				(sanitize_submodule_env; cd "$sm_path" &&
 					( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) &&
 					 test -z "$rev") || git-fetch)) ||
 				die "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'")"
@@ -787,7 +797,7 @@ Maybe you want to use 'update --init'?")"
 				die "$(eval_gettext "Invalid update mode '$update_module' for submodule '$name'")"
 			esac
 
-			if (clear_local_git_env; cd "$sm_path" && $command "$sha1")
+			if (sanitize_submodule_env; cd "$sm_path" && $command "$sha1")
 			then
 				say "$say_msg"
 			elif test -n "$must_die_on_failure"
@@ -803,7 +813,7 @@ Maybe you want to use 'update --init'?")"
 		then
 			(
 				prefix="$prefix$sm_path/"
-				clear_local_git_env
+				sanitize_submodule_env
 				cd "$sm_path" &&
 				eval cmd_update
 			)
@@ -841,7 +851,7 @@ Maybe you want to use 'update --init'?")"
 
 set_name_rev () {
 	revname=$( (
-		clear_local_git_env
+		sanitize_submodule_env
 		cd "$1" && {
 			git describe "$2" 2>/dev/null ||
 			git describe --tags "$2" 2>/dev/null ||
@@ -1125,7 +1135,7 @@ cmd_status()
 		else
 			if test -z "$cached"
 			then
-				sha1=$(clear_local_git_env; cd "$sm_path" && git rev-parse --verify HEAD)
+				sha1=$(sanitize_submodule_env; cd "$sm_path" && git rev-parse --verify HEAD)
 			fi
 			set_name_rev "$sm_path" "$sha1"
 			say "+$sha1 $displaypath$revname"
@@ -1135,7 +1145,7 @@ cmd_status()
 		then
 			(
 				prefix="$displaypath/"
-				clear_local_git_env
+				sanitize_submodule_env
 				cd "$sm_path" &&
 				eval cmd_status
 			) ||
@@ -1209,7 +1219,7 @@ cmd_sync()
 			if test -e "$sm_path"/.git
 			then
 			(
-				clear_local_git_env
+				sanitize_submodule_env
 				cd "$sm_path"
 				remote=$(get_default_remote)
 				git config remote."$remote".url "$sub_origin_url"
diff --git a/t/t5550-http-fetch-dumb.sh b/t/t5550-http-fetch-dumb.sh
index 64146352ae20..48e2ab62da7a 100755
--- a/t/t5550-http-fetch-dumb.sh
+++ b/t/t5550-http-fetch-dumb.sh
@@ -91,6 +91,23 @@ test_expect_success 'configured username does not override URL' '
 	expect_askpass pass user@host
 '
 
+test_expect_success 'cmdline credential config passes into submodules' '
+	git init super &&
+	set_askpass user@host pass@host &&
+	(
+		cd super &&
+		git submodule add "$HTTPD_URL/auth/dumb/repo.git" sub &&
+		git commit -m "add submodule"
+	) &&
+	set_askpass wrong pass@host &&
+	test_must_fail git clone --recursive super super-clone &&
+	rm -rf super-clone &&
+	set_askpass wrong pass@host &&
+	git -c "credential.$HTTP_URL.username=user@host" \
+		clone --recursive super super-clone &&
+	expect_askpass pass user@host
+'
+
 test_expect_success 'fetch changes via http' '
 	echo content >>file &&
 	git commit -a -m two &&
diff --git a/t/t7412-submodule--helper.sh b/t/t7412-submodule--helper.sh
new file mode 100755
index 000000000000..149d42864f29
--- /dev/null
+++ b/t/t7412-submodule--helper.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+#
+# Copyright (c) 2016 Jacob Keller
+#
+
+test_description='Basic plumbing support of submodule--helper
+
+This test verifies the submodule--helper plumbing command used to implement
+git-submodule.
+'
+
+. ./test-lib.sh
+
+test_expect_success 'sanitize-config clears configuration' '
+	git -c user.name="Some User" submodule--helper sanitize-config >actual &&
+	test_must_be_empty actual
+'
+
+sq="'"
+test_expect_success 'sanitize-config keeps credential.helper' '
+	git -c credential.helper=helper submodule--helper sanitize-config >actual &&
+	echo "${sq}credential.helper=helper${sq}" >expect &&
+	test_cmp expect actual
+'
+
+test_done
-- 
2.7.1.429.g45cd78e

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

* Re: [PATCH v5 0/3] pass credential.* to submodules
  2016-02-27  0:13 [PATCH v5 0/3] pass credential.* to submodules Jacob Keller
                   ` (2 preceding siblings ...)
  2016-02-27  0:13 ` [PATCH v5 3/3] git: submodule honor -c credential.* from command line Jacob Keller
@ 2016-02-27  0:37 ` Jacob Keller
  3 siblings, 0 replies; 13+ messages in thread
From: Jacob Keller @ 2016-02-27  0:37 UTC (permalink / raw)
  To: Jacob Keller
  Cc: Git mailing list, Jeff King, Mark Strapetz, Stefan Beller,
	Junio C Hamano

On Fri, Feb 26, 2016 at 4:13 PM, Jacob Keller <jacob.e.keller@intel.com> wrote:
> From: Jacob Keller <jacob.keller@gmail.com>
>
> This version of the series fixes up a few issues and implements
> sq_quotef function to help make intent more clear in the code. I also
> chose to use Jeff's implementation for the test fix since I think it
> works better and I prefer the consistency of implementation.
>

Junio, I didn't use -4 when sending email so the patch which fixes
apache.conf is not here. I still need it myself for running the test,
so it should be queued somehow.

Regards,
Jake

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

* Re: [PATCH v5 1/3] sumodule--helper: fix submodule--helper clone usage and check argc count
  2016-02-27  0:13 ` [PATCH v5 1/3] sumodule--helper: fix submodule--helper clone usage and check argc count Jacob Keller
@ 2016-02-29 17:49   ` Junio C Hamano
  2016-02-29 19:34     ` Jacob Keller
  0 siblings, 1 reply; 13+ messages in thread
From: Junio C Hamano @ 2016-02-29 17:49 UTC (permalink / raw)
  To: Jacob Keller; +Cc: git, Jeff King, Mark Strapetz, Stefan Beller, Jacob Keller

Jacob Keller <jacob.e.keller@intel.com> writes:

> From: Jacob Keller <jacob.keller@gmail.com>
>
> git submodule--helper clone usage specified that paths come after the --
> as a sequence. However, the actual implementation does not, and requires
> only a single path passed in via --path. In addition, argc was
> unchecked. (allowing arbitrary extra arguments that were silently
> ignored).
>
> Fix the usage description to match implementation. Add an argc check to
> enforce no extra arguments. 

The above sounds very sensible.

> Fix a bug in the argument passing in
> git-submodule.sh which would pass --reference and --depth as empty
> strings when they were unused, resulting in extra argc after parsing
> options.

This does make sense but it is an unrelated fix.  Perhaps split this
patch into two?

> Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
> ---
>  builtin/submodule--helper.c | 5 ++++-
>  git-submodule.sh            | 4 ++--
>  2 files changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index f4c3eff179b5..072d9bbd12a8 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -187,13 +187,16 @@ static int module_clone(int argc, const char **argv, const char *prefix)
>  	const char *const git_submodule_helper_usage[] = {
>  		N_("git submodule--helper clone [--prefix=<path>] [--quiet] "
>  		   "[--reference <repository>] [--name <name>] [--url <url>]"
> -		   "[--depth <depth>] [--] [<path>...]"),
> +		   "[--depth <depth>] [--path <path>]"),
>  		NULL
>  	};
>  
>  	argc = parse_options(argc, argv, prefix, module_clone_options,
>  			     git_submodule_helper_usage, 0);
>  
> +	if (argc)
> +		usage(*git_submodule_helper_usage);
> +

That asterisk looks very unusual and wanting to be future-proofed
(i.e. who says that only the first entry matters?).  Should't this
be calling usage_with_options()?

>  	strbuf_addf(&sb, "%s/modules/%s", get_git_dir(), name);
>  	sm_gitdir = strbuf_detach(&sb, NULL);
>  
> diff --git a/git-submodule.sh b/git-submodule.sh
> index 9bc5c5f94d1d..2dd29b3df0e6 100755
> --- a/git-submodule.sh
> +++ b/git-submodule.sh
> @@ -347,7 +347,7 @@ Use -f if you really want to add it." >&2
>  				echo "$(eval_gettext "Reactivating local git directory for submodule '\$sm_name'.")"
>  			fi
>  		fi
> -		git submodule--helper clone ${GIT_QUIET:+--quiet} --prefix "$wt_prefix" --path "$sm_path" --name "$sm_name" --url "$realrepo" "$reference" "$depth" || exit
> +		git submodule--helper clone ${GIT_QUIET:+--quiet} --prefix "$wt_prefix" --path "$sm_path" --name "$sm_name" --url "$realrepo" ${reference:+"$reference"} ${depth:+"$depth"} || exit
>  		(
>  			clear_local_git_env
>  			cd "$sm_path" &&
> @@ -709,7 +709,7 @@ Maybe you want to use 'update --init'?")"
>  
>  		if ! test -d "$sm_path"/.git && ! test -f "$sm_path"/.git
>  		then
> -			git submodule--helper clone ${GIT_QUIET:+--quiet} --prefix "$prefix" --path "$sm_path" --name "$name" --url "$url" "$reference" "$depth" || exit
> +			git submodule--helper clone ${GIT_QUIET:+--quiet} --prefix "$prefix" --path "$sm_path" --name "$name" --url "$url" ${reference:+"$reference"} ${depth:+"$depth"} || exit
>  			cloned_modules="$cloned_modules;$name"
>  			subsha1=
>  		else

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

* Re: [PATCH v5 3/3] git: submodule honor -c credential.* from command line
  2016-02-27  0:13 ` [PATCH v5 3/3] git: submodule honor -c credential.* from command line Jacob Keller
@ 2016-02-29 18:20   ` Junio C Hamano
  2016-02-29 19:37     ` Jacob Keller
  0 siblings, 1 reply; 13+ messages in thread
From: Junio C Hamano @ 2016-02-29 18:20 UTC (permalink / raw)
  To: Jacob Keller; +Cc: git, Jeff King, Mark Strapetz, Stefan Beller, Jacob Keller

Jacob Keller <jacob.e.keller@intel.com> writes:

> +static int sanitize_submodule_config(const char *var, const char *value, void *data)
> +{
> +	struct strbuf quoted = STRBUF_INIT;
> +	struct strbuf *out = data;
> +
> +	if (submodule_config_ok(var)) {
> +		if (out->len)
> +			strbuf_addch(out, ' ');
> +
> +		sq_quotef(out, "%s=%s", var, value);

Can a configuration variable that comes from the original command
line be a boolean true that is spelled without "=true", i.e. can
value be NULL here?

> +	}
> +
> +	strbuf_release(&quoted);
> +
> +	return 0;
> +}
> +
> +static void prepare_submodule_repo_env(struct argv_array *out)
> +{
> +	const char * const *var;
> +
> +	for (var = local_repo_env; *var; var++) {
> +		if (!strcmp(*var, CONFIG_DATA_ENVIRONMENT)) {
> +			struct strbuf sanitized_config = STRBUF_INIT;
> +			git_config_from_parameters(sanitize_submodule_config,
> +						   &sanitized_config);
> +			argv_array_pushf(out, "%s=%s", *var, sanitized_config.buf);
> +			strbuf_release(&sanitized_config);

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

* Re: [PATCH v5 1/3] sumodule--helper: fix submodule--helper clone usage and check argc count
  2016-02-29 17:49   ` Junio C Hamano
@ 2016-02-29 19:34     ` Jacob Keller
  2016-02-29 19:44       ` Junio C Hamano
  0 siblings, 1 reply; 13+ messages in thread
From: Jacob Keller @ 2016-02-29 19:34 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Jacob Keller, Git mailing list, Jeff King, Mark Strapetz,
	Stefan Beller

On Mon, Feb 29, 2016 at 9:49 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Jacob Keller <jacob.e.keller@intel.com> writes:
>> Fix the usage description to match implementation. Add an argc check to
>> enforce no extra arguments.
>
> The above sounds very sensible.
>

Right.

>> Fix a bug in the argument passing in
>> git-submodule.sh which would pass --reference and --depth as empty
>> strings when they were unused, resulting in extra argc after parsing
>> options.
>
> This does make sense but it is an unrelated fix.  Perhaps split this
> patch into two?
>

That actually is required because otherwise adding a check for argc
would break the things. I could split them and do this first and then
check for argc if you really prefer?

>> +     if (argc)
>> +             usage(*git_submodule_helper_usage);
>> +
>
> That asterisk looks very unusual and wanting to be future-proofed
> (i.e. who says that only the first entry matters?).  Should't this
> be calling usage_with_options()?
>

I... didn't know usage_with_options was a thing! Hah. I can fix these up.

Thanks,
Jake\

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

* Re: [PATCH v5 3/3] git: submodule honor -c credential.* from command line
  2016-02-29 18:20   ` Junio C Hamano
@ 2016-02-29 19:37     ` Jacob Keller
  2016-02-29 19:47       ` Junio C Hamano
  0 siblings, 1 reply; 13+ messages in thread
From: Jacob Keller @ 2016-02-29 19:37 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Jacob Keller, Git mailing list, Jeff King, Mark Strapetz,
	Stefan Beller

On Mon, Feb 29, 2016 at 10:20 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Jacob Keller <jacob.e.keller@intel.com> writes:
>
>> +static int sanitize_submodule_config(const char *var, const char *value, void *data)
>> +{
>> +     struct strbuf quoted = STRBUF_INIT;
>> +     struct strbuf *out = data;
>> +
>> +     if (submodule_config_ok(var)) {
>> +             if (out->len)
>> +                     strbuf_addch(out, ' ');
>> +
>> +             sq_quotef(out, "%s=%s", var, value);
>
> Can a configuration variable that comes from the original command
> line be a boolean true that is spelled without "=true", i.e. can
> value be NULL here?
>

Wouldn't it just be the empty string? I'm not sure. I suppose I can do:

sq_quotef(out, "%s=%s, var, value ? value : "")

Or something?

Thanks
Jake

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

* Re: [PATCH v5 1/3] sumodule--helper: fix submodule--helper clone usage and check argc count
  2016-02-29 19:34     ` Jacob Keller
@ 2016-02-29 19:44       ` Junio C Hamano
  2016-02-29 22:05         ` Jacob Keller
  0 siblings, 1 reply; 13+ messages in thread
From: Junio C Hamano @ 2016-02-29 19:44 UTC (permalink / raw)
  To: Jacob Keller
  Cc: Jacob Keller, Git mailing list, Jeff King, Mark Strapetz,
	Stefan Beller

Jacob Keller <jacob.keller@gmail.com> writes:

>> This does make sense but it is an unrelated fix.  Perhaps split this
>> patch into two?
>
> That actually is required because otherwise adding a check for argc
> would break the things. I could split them and do this first and then
> check for argc if you really prefer?

It is not "check for argc breaks", it is already broken and by
checking for argc you are exposing the breakage, no?

So I'd say fix that first and then fix the clone subcommand?


>
>>> +     if (argc)
>>> +             usage(*git_submodule_helper_usage);
>>> +
>>
>> That asterisk looks very unusual and wanting to be future-proofed
>> (i.e. who says that only the first entry matters?).  Should't this
>> be calling usage_with_options()?
>>
>
> I... didn't know usage_with_options was a thing! Hah. I can fix these up.
>
> Thanks,
> Jake\

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

* Re: [PATCH v5 3/3] git: submodule honor -c credential.* from command line
  2016-02-29 19:37     ` Jacob Keller
@ 2016-02-29 19:47       ` Junio C Hamano
  2016-02-29 22:09         ` Jacob Keller
  0 siblings, 1 reply; 13+ messages in thread
From: Junio C Hamano @ 2016-02-29 19:47 UTC (permalink / raw)
  To: Jacob Keller
  Cc: Jacob Keller, Git mailing list, Jeff King, Mark Strapetz,
	Stefan Beller

Jacob Keller <jacob.keller@gmail.com> writes:

> On Mon, Feb 29, 2016 at 10:20 AM, Junio C Hamano <gitster@pobox.com> wrote:
>> Jacob Keller <jacob.e.keller@intel.com> writes:
>>
>>> +static int sanitize_submodule_config(const char *var, const char *value, void *data)
>>> +{
>>> +     struct strbuf quoted = STRBUF_INIT;
>>> +     struct strbuf *out = data;
>>> +
>>> +     if (submodule_config_ok(var)) {
>>> +             if (out->len)
>>> +                     strbuf_addch(out, ' ');
>>> +
>>> +             sq_quotef(out, "%s=%s", var, value);
>>
>> Can a configuration variable that comes from the original command
>> line be a boolean true that is spelled without "=true", i.e. can
>> value be NULL here?
>>
>
> Wouldn't it just be the empty string?

I was talking about the "not even an equal sign" true, i.e.

    $ git -c random.what -c random.false=no -c random.true=yes \
      config --bool --get-regexp 'random.*'
    random.what true
    random.false false
    random.true true

What would you see for random.what in the above function (if the
callchain allowed you to pass it through)?

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

* Re: [PATCH v5 1/3] sumodule--helper: fix submodule--helper clone usage and check argc count
  2016-02-29 19:44       ` Junio C Hamano
@ 2016-02-29 22:05         ` Jacob Keller
  0 siblings, 0 replies; 13+ messages in thread
From: Jacob Keller @ 2016-02-29 22:05 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Jacob Keller, Git mailing list, Jeff King, Mark Strapetz,
	Stefan Beller

On Mon, Feb 29, 2016 at 11:44 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Jacob Keller <jacob.keller@gmail.com> writes:
>> That actually is required because otherwise adding a check for argc
>> would break the things. I could split them and do this first and then
>> check for argc if you really prefer?
>
> It is not "check for argc breaks", it is already broken and by
> checking for argc you are exposing the breakage, no?
>
> So I'd say fix that first and then fix the clone subcommand?
>

Ok, so one patch which fixes the empty string arguments first, then
the second patch which adds the (now valid) check?

Thanks,
Jake

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

* Re: [PATCH v5 3/3] git: submodule honor -c credential.* from command line
  2016-02-29 19:47       ` Junio C Hamano
@ 2016-02-29 22:09         ` Jacob Keller
  0 siblings, 0 replies; 13+ messages in thread
From: Jacob Keller @ 2016-02-29 22:09 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Jacob Keller, Git mailing list, Jeff King, Mark Strapetz,
	Stefan Beller

On Mon, Feb 29, 2016 at 11:47 AM, Junio C Hamano <gitster@pobox.com> wrote:
> I was talking about the "not even an equal sign" true, i.e.
>
>     $ git -c random.what -c random.false=no -c random.true=yes \
>       config --bool --get-regexp 'random.*'
>     random.what true
>     random.false false
>     random.true true
>
> What would you see for random.what in the above function (if the
> callchain allowed you to pass it through)?

I see 'credential.what=(null)' if I pass it to sanitize-config. That's
probably a bug, and we should instead just output 'credential.what'
instead. I'll rework this.

Thanks,
Jake

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

end of thread, other threads:[~2016-02-29 22:09 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-27  0:13 [PATCH v5 0/3] pass credential.* to submodules Jacob Keller
2016-02-27  0:13 ` [PATCH v5 1/3] sumodule--helper: fix submodule--helper clone usage and check argc count Jacob Keller
2016-02-29 17:49   ` Junio C Hamano
2016-02-29 19:34     ` Jacob Keller
2016-02-29 19:44       ` Junio C Hamano
2016-02-29 22:05         ` Jacob Keller
2016-02-27  0:13 ` [PATCH v5 2/3] quote: implement sq_quotef() Jacob Keller
2016-02-27  0:13 ` [PATCH v5 3/3] git: submodule honor -c credential.* from command line Jacob Keller
2016-02-29 18:20   ` Junio C Hamano
2016-02-29 19:37     ` Jacob Keller
2016-02-29 19:47       ` Junio C Hamano
2016-02-29 22:09         ` Jacob Keller
2016-02-27  0:37 ` [PATCH v5 0/3] pass credential.* to submodules Jacob Keller

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).