{"thread":{"id":"41537","subject":"[PATCH v3 2/3] sumodule--helper: fix submodule--helper clone usage and check argc count","startedAt":"2016-02-26T19:17:46Z","lastAt":"2016-02-26T22:19:32Z","messageCount":5,"participants":["Jacob Keller","Stefan Beller"],"isPatch":true,"patchVersion":3,"patchTotal":3},"messages":[{"id":"279551","messageId":"1456514268-8241-1-git-send-email-jacob.e.keller@intel.com","threadId":"41537","inReplyTo":null,"subject":"[PATCH v3 1/3] t/lib-httpd: load mod_unixd","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2016-02-26T19:17:46Z","receivedAt":"2016-02-26T19:17:46Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Michael J Gruber <git@drmicha.warpmail.net>\n\nIn contrast to apache 2.2, apache 2.4 does not load mod_unixd in its\ndefault configuration (because there are choices). Thus, with the\ncurrent config, apache 2.4.10 will not be started and the httpd tests\nwill not run on distros with default apache config (RedHat type).\n\nEnable mod_unixd to make the httpd tests run. This does not affect\ndistros negatively which have that config already in their default\n(Debian type). httpd tests will run on these before and after this patch.\n\nSigned-off-by: Michael J Gruber <git@drmicha.warpmail.net>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\nI am resending this as part of my series, although I have made zero\nedits from what was on pu, only to show that I need this to get my\nsystem to pass the httpd tests.\n\n t/lib-httpd/apache.conf | 3 +++\n 1 file changed, 3 insertions(+)\n\ndiff --git a/t/lib-httpd/apache.conf b/t/lib-httpd/apache.conf\nindex 7d15e6d44c83..f667e7ce2f33 100644\n--- a/t/lib-httpd/apache.conf\n+++ b/t/lib-httpd/apache.conf\n@@ -64,6 +64,9 @@ LockFile accept.lock\n <IfModule !mod_mpm_prefork.c>\n \tLoadModule mpm_prefork_module modules/mod_mpm_prefork.so\n </IfModule>\n+<IfModule !mod_unixd.c>\n+\tLoadModule unixd_module modules/mod_unixd.so\n+</IfModule>\n </IfVersion>\n \n PassEnv GIT_VALGRIND\n-- \n2.7.1.429.g45cd78e\n"},{"id":"279550","messageId":"1456514268-8241-2-git-send-email-jacob.e.keller@intel.com","threadId":"41537","inReplyTo":"1456514268-8241-1-git-send-email-jacob.e.keller@intel.com","subject":"[PATCH v3 2/3] sumodule--helper: fix submodule--helper clone usage and check argc count","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2016-02-26T19:17:47Z","receivedAt":"2016-02-26T19:17:47Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\ngit submodule--helper clone usage specified that paths come after the --\nas a sequence. However, the actual implementation does not, and requires\nonly a single path passed in via --path. In addition, argc was\nunchecked. (allowing arbitrary extra arguments that were silently\nignored).\n\nFix the usage description to match implementation. Add an argc check to\nenforce no extra arguments. Fix a bug in the argument passing in\ngit-submodule.sh which would pass --reference and --depth as empty\nstrings when they were unused, resulting in extra argc after parsing\noptions.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\nAfter adding argc check to my new sanitize-config subcommand, I realized\nthat submodule--helper clone was the only one without an argc check.\nWhen I went to add it, I realized the usage was incorrect, and the\nimplementation in git-submodule.sh results in extra arguments being\npassed.\n\nI am not sure this is the best way to resolve these, but I wanted to\ninclude it since I think silently accepting extra arguments we don't use\nis bad.\n\n builtin/submodule--helper.c | 5 ++++-\n git-submodule.sh            | 4 ++--\n 2 files changed, 6 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex f4c3eff179b5..072d9bbd12a8 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -187,13 +187,16 @@ static int module_clone(int argc, const char **argv, const char *prefix)\n \tconst char *const git_submodule_helper_usage[] = {\n \t\tN_(\"git submodule--helper clone [--prefix=<path>] [--quiet] \"\n \t\t   \"[--reference <repository>] [--name <name>] [--url <url>]\"\n-\t\t   \"[--depth <depth>] [--] [<path>...]\"),\n+\t\t   \"[--depth <depth>] [--path <path>]\"),\n \t\tNULL\n \t};\n \n \targc = parse_options(argc, argv, prefix, module_clone_options,\n \t\t\t     git_submodule_helper_usage, 0);\n \n+\tif (argc)\n+\t\tusage(*git_submodule_helper_usage);\n+\n \tstrbuf_addf(&sb, \"%s/modules/%s\", get_git_dir(), name);\n \tsm_gitdir = strbuf_detach(&sb, NULL);\n \ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 9bc5c5f94d1d..2dd29b3df0e6 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -347,7 +347,7 @@ Use -f if you really want to add it.\" >&2\n \t\t\t\techo \"$(eval_gettext \"Reactivating local git directory for submodule '\\$sm_name'.\")\"\n \t\t\tfi\n \t\tfi\n-\t\tgit submodule--helper clone ${GIT_QUIET:+--quiet} --prefix \"$wt_prefix\" --path \"$sm_path\" --name \"$sm_name\" --url \"$realrepo\" \"$reference\" \"$depth\" || exit\n+\t\tgit submodule--helper clone ${GIT_QUIET:+--quiet} --prefix \"$wt_prefix\" --path \"$sm_path\" --name \"$sm_name\" --url \"$realrepo\" ${reference:+\"$reference\"} ${depth:+\"$depth\"} || exit\n \t\t(\n \t\t\tclear_local_git_env\n \t\t\tcd \"$sm_path\" &&\n@@ -709,7 +709,7 @@ Maybe you want to use 'update --init'?\")\"\n \n \t\tif ! test -d \"$sm_path\"/.git && ! test -f \"$sm_path\"/.git\n \t\tthen\n-\t\t\tgit submodule--helper clone ${GIT_QUIET:+--quiet} --prefix \"$prefix\" --path \"$sm_path\" --name \"$name\" --url \"$url\" \"$reference\" \"$depth\" || exit\n+\t\t\tgit submodule--helper clone ${GIT_QUIET:+--quiet} --prefix \"$prefix\" --path \"$sm_path\" --name \"$name\" --url \"$url\" ${reference:+\"$reference\"} ${depth:+\"$depth\"} || exit\n \t\t\tcloned_modules=\"$cloned_modules;$name\"\n \t\t\tsubsha1=\n \t\telse\n-- \n2.7.1.429.g45cd78e\n"},{"id":"279552","messageId":"1456514268-8241-3-git-send-email-jacob.e.keller@intel.com","threadId":"41537","inReplyTo":"1456514268-8241-1-git-send-email-jacob.e.keller@intel.com","subject":"[PATCH v3 3/3] git: submodule honor -c credential.* from command line","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2016-02-26T19:17:48Z","receivedAt":"2016-02-26T19:17:48Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\nDue to the way that the git-submodule code works, it clears all local\ngit environment variables before entering submodules. This is normally\na good thing since we want to clear settings such as GIT_WORKTREE and\nother variables which would affect the operation of submodule commands.\nHowever, GIT_CONFIG_PARAMETERS is special, and we actually do want to\npreserve these settings. However, we do not want to preserve all\nconfiguration as many things should be left specific to the parent\nproject.\n\nAdd a git submodule--helper function, sanitize-config, which shall be\nused to sanitize GIT_CONFIG_PARAMETERS, removing all key/value pairs\nexcept a small subset that are known to be safe and necessary.\n\nReplace all the calls to clear_local_git_env with a wrapped function\nthat filters GIT_CONFIG_PARAMETERS using the new helper and then\nrestores it to the filtered subset after clearing the rest of the\nenvironment.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n\nNotes:\n    - v2\n    * Clarify which paramaters are left after the sanitization, and don't seem to\n      indicate it is our goal to extend the list.\n    * add a comment in the submodule_config_ok function indicating the same\n\n    - v3\n    * Remove extraneous comments\n    * add strbuf_release calls\n    * rename sanitize_local_git_env\n    * remove use of local\n    * add C equivalent of sanitize_config\n    * add a test for the credential passing\n\n    - v3\n    * use argc check instead of empty options check\n    * fix brain-melting quotes in t7412-submodule--helper.sh\n\n builtin/submodule--helper.c  | 77 +++++++++++++++++++++++++++++++++++++++++++-\n git-submodule.sh             | 36 +++++++++++++--------\n t/t5550-http-fetch-dumb.sh   | 17 ++++++++++\n t/t7412-submodule--helper.sh | 27 ++++++++++++++++\n 4 files changed, 143 insertions(+), 14 deletions(-)\n create mode 100755 t/t7412-submodule--helper.sh\n\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 072d9bbd12a8..c6c0a3b06e27 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -124,6 +124,64 @@ static int module_name(int argc, const char **argv, const char *prefix)\n \n \treturn 0;\n }\n+\n+/*\n+ * Rules to sanitize configuration variables that are Ok to be passed into\n+ * submodule operations from the parent project using \"-c\". Should only\n+ * include keys which are both (a) safe and (b) necessary for proper\n+ * operation.\n+ */\n+static int submodule_config_ok(const char *var)\n+{\n+\tif (starts_with(var, \"credential.\"))\n+\t\treturn 1;\n+\treturn 0;\n+}\n+\n+static int sanitize_submodule_config(const char *var, const char *value, void *data)\n+{\n+\tstruct strbuf quoted = STRBUF_INIT;\n+\tstruct strbuf *out = data;\n+\n+\tif (submodule_config_ok(var)) {\n+\t\tif (out->len)\n+\t\t\tstrbuf_addch(out, ' ');\n+\n+\t\t/*\n+\t\t * The GIT_CONFIG_PARAMETERS parser is a bit picky and\n+\t\t * requires that each var=value pair be quoted as a single\n+\t\t * unit.\n+\t\t */\n+\t\tstrbuf_addstr(&quoted, var);\n+\t\tstrbuf_addch(&quoted, '=');\n+\t\tstrbuf_addstr(&quoted, value);\n+\n+\t\tsq_quote_buf(out, quoted.buf);\n+\t}\n+\n+\tstrbuf_release(&quoted);\n+\n+\treturn 0;\n+}\n+\n+static void prepare_submodule_repo_env(struct argv_array *out)\n+{\n+\tconst char * const *var;\n+\n+\tfor (var = local_repo_env; *var; var++) {\n+\t\tif (!strcmp(*var, CONFIG_DATA_ENVIRONMENT)) {\n+\t\t\tstruct strbuf sanitized_config = STRBUF_INIT;\n+\t\t\tgit_config_from_parameters(sanitize_submodule_config,\n+\t\t\t\t\t\t   &sanitized_config);\n+\t\t\targv_array_pushf(out, \"%s=%s\", *var, sanitized_config.buf);\n+\t\t\tstrbuf_release(&sanitized_config);\n+\t\t} else {\n+\t\t\targv_array_push(out, *var);\n+\t\t}\n+\t}\n+\n+}\n+\n static int clone_submodule(const char *path, const char *gitdir, const char *url,\n \t\t\t   const char *depth, const char *reference, int quiet)\n {\n@@ -145,7 +203,7 @@ static int clone_submodule(const char *path, const char *gitdir, const char *url\n \targv_array_push(&cp.args, path);\n \n \tcp.git_cmd = 1;\n-\tcp.env = local_repo_env;\n+\tprepare_submodule_repo_env(&cp.env_array);\n \tcp.no_stdin = 1;\n \n \treturn run_command(&cp);\n@@ -258,6 +316,22 @@ static int module_clone(int argc, const char **argv, const char *prefix)\n \treturn 0;\n }\n \n+static int module_sanitize_config(int argc, const char **argv, const char *prefix)\n+{\n+\tstruct strbuf sanitized_config = STRBUF_INIT;\n+\n+\tif (argc > 1)\n+\t\tusage(_(\"git submodule--helper sanitize-config\"));\n+\n+\tgit_config_from_parameters(sanitize_submodule_config, &sanitized_config);\n+\tif (sanitized_config.len)\n+\t\tprintf(\"%s\\n\", sanitized_config.buf);\n+\n+\tstrbuf_release(&sanitized_config);\n+\n+\treturn 0;\n+}\n+\n struct cmd_struct {\n \tconst char *cmd;\n \tint (*fn)(int, const char **, const char *);\n@@ -267,6 +341,7 @@ static struct cmd_struct commands[] = {\n \t{\"list\", module_list},\n \t{\"name\", module_name},\n \t{\"clone\", module_clone},\n+\t{\"sanitize-config\", module_sanitize_config},\n };\n \n int cmd_submodule__helper(int argc, const char **argv, const char *prefix)\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 2dd29b3df0e6..1f132b489b81 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -192,6 +192,16 @@ isnumber()\n \tn=$(($1 + 0)) 2>/dev/null && test \"$n\" = \"$1\"\n }\n \n+# Sanitize the local git environment for use within a submodule. We\n+# can't simply use clear_local_git_env since we want to preserve some\n+# of the settings from GIT_CONFIG_PARAMETERS.\n+sanitize_submodule_env()\n+{\n+\tsanitized_config=$(git submodule--helper sanitize-config)\n+\tclear_local_git_env\n+\tGIT_CONFIG_PARAMETERS=$sanitized_config\n+}\n+\n #\n # Add a new submodule to the working tree, .gitmodules and the index\n #\n@@ -349,7 +359,7 @@ Use -f if you really want to add it.\" >&2\n \t\tfi\n \t\tgit submodule--helper clone ${GIT_QUIET:+--quiet} --prefix \"$wt_prefix\" --path \"$sm_path\" --name \"$sm_name\" --url \"$realrepo\" ${reference:+\"$reference\"} ${depth:+\"$depth\"} || exit\n \t\t(\n-\t\t\tclear_local_git_env\n+\t\t\tsanitize_submodule_env\n \t\t\tcd \"$sm_path\" &&\n \t\t\t# ash fails to wordsplit ${branch:+-b \"$branch\"...}\n \t\t\tcase \"$branch\" in\n@@ -418,7 +428,7 @@ cmd_foreach()\n \t\t\tname=$(git submodule--helper name \"$sm_path\")\n \t\t\t(\n \t\t\t\tprefix=\"$prefix$sm_path/\"\n-\t\t\t\tclear_local_git_env\n+\t\t\t\tsanitize_submodule_env\n \t\t\t\tcd \"$sm_path\" &&\n \t\t\t\tsm_path=$(relative_path \"$sm_path\") &&\n \t\t\t\t# we make $path available to scripts ...\n@@ -713,7 +723,7 @@ Maybe you want to use 'update --init'?\")\"\n \t\t\tcloned_modules=\"$cloned_modules;$name\"\n \t\t\tsubsha1=\n \t\telse\n-\t\t\tsubsha1=$(clear_local_git_env; cd \"$sm_path\" &&\n+\t\t\tsubsha1=$(sanitize_submodule_env; cd \"$sm_path\" &&\n \t\t\t\tgit rev-parse --verify HEAD) ||\n \t\t\tdie \"$(eval_gettext \"Unable to find current revision in submodule path '\\$displaypath'\")\"\n \t\tfi\n@@ -723,11 +733,11 @@ Maybe you want to use 'update --init'?\")\"\n \t\t\tif test -z \"$nofetch\"\n \t\t\tthen\n \t\t\t\t# Fetch remote before determining tracking $sha1\n-\t\t\t\t(clear_local_git_env; cd \"$sm_path\" && git-fetch) ||\n+\t\t\t\t(sanitize_submodule_env; cd \"$sm_path\" && git-fetch) ||\n \t\t\t\tdie \"$(eval_gettext \"Unable to fetch in submodule path '\\$sm_path'\")\"\n \t\t\tfi\n-\t\t\tremote_name=$(clear_local_git_env; cd \"$sm_path\" && get_default_remote)\n-\t\t\tsha1=$(clear_local_git_env; cd \"$sm_path\" &&\n+\t\t\tremote_name=$(sanitize_submodule_env; cd \"$sm_path\" && get_default_remote)\n+\t\t\tsha1=$(sanitize_submodule_env; cd \"$sm_path\" &&\n \t\t\t\tgit rev-parse --verify \"${remote_name}/${branch}\") ||\n \t\t\tdie \"$(eval_gettext \"Unable to find current ${remote_name}/${branch} revision in submodule path '\\$sm_path'\")\"\n \t\tfi\n@@ -745,7 +755,7 @@ Maybe you want to use 'update --init'?\")\"\n \t\t\tthen\n \t\t\t\t# Run fetch only if $sha1 isn't present or it\n \t\t\t\t# is not reachable from a ref.\n-\t\t\t\t(clear_local_git_env; cd \"$sm_path\" &&\n+\t\t\t\t(sanitize_submodule_env; cd \"$sm_path\" &&\n \t\t\t\t\t( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) &&\n \t\t\t\t\t test -z \"$rev\") || git-fetch)) ||\n \t\t\t\tdie \"$(eval_gettext \"Unable to fetch in submodule path '\\$displaypath'\")\"\n@@ -787,7 +797,7 @@ Maybe you want to use 'update --init'?\")\"\n \t\t\t\tdie \"$(eval_gettext \"Invalid update mode '$update_module' for submodule '$name'\")\"\n \t\t\tesac\n \n-\t\t\tif (clear_local_git_env; cd \"$sm_path\" && $command \"$sha1\")\n+\t\t\tif (sanitize_submodule_env; cd \"$sm_path\" && $command \"$sha1\")\n \t\t\tthen\n \t\t\t\tsay \"$say_msg\"\n \t\t\telif test -n \"$must_die_on_failure\"\n@@ -803,7 +813,7 @@ Maybe you want to use 'update --init'?\")\"\n \t\tthen\n \t\t\t(\n \t\t\t\tprefix=\"$prefix$sm_path/\"\n-\t\t\t\tclear_local_git_env\n+\t\t\t\tsanitize_submodule_env\n \t\t\t\tcd \"$sm_path\" &&\n \t\t\t\teval cmd_update\n \t\t\t)\n@@ -841,7 +851,7 @@ Maybe you want to use 'update --init'?\")\"\n \n set_name_rev () {\n \trevname=$( (\n-\t\tclear_local_git_env\n+\t\tsanitize_submodule_env\n \t\tcd \"$1\" && {\n \t\t\tgit describe \"$2\" 2>/dev/null ||\n \t\t\tgit describe --tags \"$2\" 2>/dev/null ||\n@@ -1125,7 +1135,7 @@ cmd_status()\n \t\telse\n \t\t\tif test -z \"$cached\"\n \t\t\tthen\n-\t\t\t\tsha1=$(clear_local_git_env; cd \"$sm_path\" && git rev-parse --verify HEAD)\n+\t\t\t\tsha1=$(sanitize_submodule_env; cd \"$sm_path\" && git rev-parse --verify HEAD)\n \t\t\tfi\n \t\t\tset_name_rev \"$sm_path\" \"$sha1\"\n \t\t\tsay \"+$sha1 $displaypath$revname\"\n@@ -1135,7 +1145,7 @@ cmd_status()\n \t\tthen\n \t\t\t(\n \t\t\t\tprefix=\"$displaypath/\"\n-\t\t\t\tclear_local_git_env\n+\t\t\t\tsanitize_submodule_env\n \t\t\t\tcd \"$sm_path\" &&\n \t\t\t\teval cmd_status\n \t\t\t) ||\n@@ -1209,7 +1219,7 @@ cmd_sync()\n \t\t\tif test -e \"$sm_path\"/.git\n \t\t\tthen\n \t\t\t(\n-\t\t\t\tclear_local_git_env\n+\t\t\t\tsanitize_submodule_env\n \t\t\t\tcd \"$sm_path\"\n \t\t\t\tremote=$(get_default_remote)\n \t\t\t\tgit config remote.\"$remote\".url \"$sub_origin_url\"\ndiff --git a/t/t5550-http-fetch-dumb.sh b/t/t5550-http-fetch-dumb.sh\nindex 64146352ae20..48e2ab62da7a 100755\n--- a/t/t5550-http-fetch-dumb.sh\n+++ b/t/t5550-http-fetch-dumb.sh\n@@ -91,6 +91,23 @@ test_expect_success 'configured username does not override URL' '\n \texpect_askpass pass user@host\n '\n \n+test_expect_success 'cmdline credential config passes into submodules' '\n+\tgit init super &&\n+\tset_askpass user@host pass@host &&\n+\t(\n+\t\tcd super &&\n+\t\tgit submodule add \"$HTTPD_URL/auth/dumb/repo.git\" sub &&\n+\t\tgit commit -m \"add submodule\"\n+\t) &&\n+\tset_askpass wrong pass@host &&\n+\ttest_must_fail git clone --recursive super super-clone &&\n+\trm -rf super-clone &&\n+\tset_askpass wrong pass@host &&\n+\tgit -c \"credential.$HTTP_URL.username=user@host\" \\\n+\t\tclone --recursive super super-clone &&\n+\texpect_askpass pass user@host\n+'\n+\n test_expect_success 'fetch changes via http' '\n \techo content >>file &&\n \tgit commit -a -m two &&\ndiff --git a/t/t7412-submodule--helper.sh b/t/t7412-submodule--helper.sh\nnew file mode 100755\nindex 000000000000..9d937de8b224\n--- /dev/null\n+++ b/t/t7412-submodule--helper.sh\n@@ -0,0 +1,27 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2016 Jacob Keller\n+#\n+\n+test_description='Basic plumbing support of submodule--helper\n+\n+This test verifies the submodule--helper plumbing command used to implement\n+git-submodule.\n+'\n+\n+. ./test-lib.sh\n+\n+test_expect_success 'sanitize-config clears configuration' '\n+\tgit -c user.name=\"Some User\" submodule--helper sanitize-config >actual &&\n+\ttest_must_be_empty actual\n+'\n+\n+test_expect_success 'sanitize-config keeps credential.helper' \"\n+\tgit -c credential.helper=helper submodule--helper sanitize-config >actual &&\n+\tcat >expect <<-EOF &&\n+\t'credential.helper=helper'\n+\tEOF\n+\ttest_cmp expect actual\n+\"\n+\n+test_done\n-- \n2.7.1.429.g45cd78e\n"},{"id":"279558","messageId":"CAGZ79kZnR3EsESCFdORq84awWnRZZ9A_+mcH_54ULZZJfD8xyQ@mail.gmail.com","threadId":"41537","inReplyTo":"1456514268-8241-3-git-send-email-jacob.e.keller@intel.com","subject":"Re: [PATCH v3 3/3] git: submodule honor -c credential.* from command line","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-02-26T19:41:15Z","receivedAt":"2016-02-26T19:41:15Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Fri, Feb 26, 2016 at 11:17 AM, Jacob Keller <jacob.e.keller@intel.com> wrote:\n> From: Jacob Keller <jacob.keller@gmail.com>\n>\n> Due to the way that the git-submodule code works, it clears all local\n> git environment variables before entering submodules. This is normally\n> a good thing since we want to clear settings such as GIT_WORKTREE and\n> other variables which would affect the operation of submodule commands.\n> However, GIT_CONFIG_PARAMETERS is special, and we actually do want to\n> preserve these settings. However, we do not want to preserve all\n> configuration as many things should be left specific to the parent\n> project.\n>\n> Add a git submodule--helper function, sanitize-config, which shall be\n> used to sanitize GIT_CONFIG_PARAMETERS, removing all key/value pairs\n> except a small subset that are known to be safe and necessary.\n>\n> Replace all the calls to clear_local_git_env with a wrapped function\n> that filters GIT_CONFIG_PARAMETERS using the new helper and then\n> restores it to the filtered subset after clearing the rest of the\n> environment.\n>\n> Signed-off-by: Jacob Keller <jacob.keller@gmail.com>\n> ---\n>\n> Notes:\n>     - v2\n>     * Clarify which paramaters are left after the sanitization, and don't seem to\n>       indicate it is our goal to extend the list.\n>     * add a comment in the submodule_config_ok function indicating the same\n>\n>     - v3\n>     * Remove extraneous comments\n>     * add strbuf_release calls\n>     * rename sanitize_local_git_env\n>     * remove use of local\n>     * add C equivalent of sanitize_config\n>     * add a test for the credential passing\n>\n>     - v3\n>     * use argc check instead of empty options check\n>     * fix brain-melting quotes in t7412-submodule--helper.sh\n\nIn the future, would you mind to try interdiffs in a cover letter?\n\n(I do git diff HEAD...$(previousSeries) with previousSerier either\nlocal branch or rather what Junio picked up already. There is also tbdiff,\nwhich should be better and easier than this work flow)\n\n\n> +                */\n> +               strbuf_addstr(&quoted, var);\n> +               strbuf_addch(&quoted, '=');\n> +               strbuf_addstr(&quoted, value);\n\nThis could be `strbuf_addf(\"%s=%s\", var, value);` (?)\nwhich then gets quoted below\n\n> +                       git_config_from_parameters(sanitize_submodule_config,\n> +                                                  &sanitized_config);\n> +                       argv_array_pushf(out, \"%s=%s\", *var, sanitized_config.buf);\n\nlike here?\n\n> -                       subsha1=$(clear_local_git_env; cd \"$sm_path\" &&\n> +                       subsha1=$(sanitize_submodule_env; cd \"$sm_path\" &&\n>                                 git rev-parse --verify HEAD) ||\n\nWhile at it, we could discuss if we want to replace the pattern cd\n<somewhere> && git-command\nby `git -C <somewhere> <command>` eventually (not in this patch) ?\n"},{"id":"279575","messageId":"CA+P7+xpArLkv2_3juxMFBct1=31hf-gdaOT43pN9CbpuHaz5AQ@mail.gmail.com","threadId":"41537","inReplyTo":"CAGZ79kZnR3EsESCFdORq84awWnRZZ9A_+mcH_54ULZZJfD8xyQ@mail.gmail.com","subject":"Re: [PATCH v3 3/3] git: submodule honor -c credential.* from command line","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2016-02-26T22:19:32Z","receivedAt":"2016-02-26T22:19:32Z","isPatch":true,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Fri, Feb 26, 2016 at 11:41 AM, Stefan Beller <sbeller@google.com> wrote:\n>\n> In the future, would you mind to try interdiffs in a cover letter?\n>\n> (I do git diff HEAD...$(previousSeries) with previousSerier either\n> local branch or rather what Junio picked up already. There is also tbdiff,\n> which should be better and easier than this work flow)\n>\n\nYes, I should do that. I could just use the reflog for this actually,\nfor my workflow.\n\n>\n>> +                */\n>> +               strbuf_addstr(&quoted, var);\n>> +               strbuf_addch(&quoted, '=');\n>> +               strbuf_addstr(&quoted, value);\n>\n> This could be `strbuf_addf(\"%s=%s\", var, value);` (?)\n> which then gets quoted below\n>\n\nIs there such a thing as sq_quote_buf equivalent of this? If not,\nshould I add one? I think that might be preferable since we'd drop the\nentire extra strbuf variable.\n\n>> +                       git_config_from_parameters(sanitize_submodule_config,\n>> +                                                  &sanitized_config);\n>> +                       argv_array_pushf(out, \"%s=%s\", *var, sanitized_config.buf);\n>\n> like here?\n>\n\nYa, I just wasn't thinking of strbuf_addf. But I think I'd rather have\nsq_quote_f or something created instead to drop the need of a separate\nstrbuf.\n\n>> -                       subsha1=$(clear_local_git_env; cd \"$sm_path\" &&\n>> +                       subsha1=$(sanitize_submodule_env; cd \"$sm_path\" &&\n>>                                 git rev-parse --verify HEAD) ||\n>\n> While at it, we could discuss if we want to replace the pattern cd\n> <somewhere> && git-command\n> by `git -C <somewhere> <command>` eventually (not in this patch) ?\n\nYes, we should use git -C instead, but probably not worth too much\neffort if our plan is to drop the shell code eventually? Might be\nworth the cleanup, especially if it lets us avoid a subshell. If we\nstill need the subshell for other non-git commands I would prefer to\nleave it as \"(cd <somewhere> && git command && other commands && ...\n&& )\n\nThanks,\nJake\n"}]}