{"thread":{"id":"22760","subject":"[PATCH] submodules: ensure clean environment when operating in a submodule","startedAt":"2010-02-22T22:16:55Z","lastAt":"2010-02-23T21:47:18Z","messageCount":15,"participants":["Giuseppe Bilotta","Junio C Hamano","Johannes Schindelin","Johannes Sixt","Jens Lehmann","Heiko Voigt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"135346","messageId":"1266877015-7943-1-git-send-email-giuseppe.bilotta@gmail.com","threadId":"22760","inReplyTo":"20100218203726.GD12660@book.hvoigt.net","subject":"[PATCH] submodules: ensure clean environment when operating in a submodule","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-02-22T22:16:55Z","receivedAt":"2010-02-22T22:16:55Z","isPatch":true,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"git-submodule takes care of clearing GIT_DIR whenever it operates\non a submodule index or configuration, but forgot to unset GIT_WORK_TREE\nbefore operating on the submodule worktree, which would lead to failures\nwhen GIT_WORK_TREE was set.\n\nThis only happened in very unusual contexts such as operating on the\nmain worktree from outside of it, but since \"git-gui: set GIT_DIR and\nGIT_WORK_TREE after setup\" (a9fa11fe5bd5978bb) such failures could also\nbe provoked by invoking an external tool such as \"git submodule update\"\nfrom the Git GUI in a standard setup.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n git-submodule.sh |    5 ++++-\n 1 files changed, 4 insertions(+), 1 deletions(-)\n\nThe bug (git submodules not working in Git GUI since my patch) was spotted by\nHeiko Voigt working on/with msysgit, and he kindly provided a recipe to\nreplicate it:\nhttp://article.gmane.org/gmane.comp.version-control.msysgit/8755\n\nI'm pretty confident fixing this on the submodules side is the more correct\napproach, since otherwise even a simple\n$ GIT_WORK_TREE=. git submodule update\non the command-line can fail.\n\nI also believe this is material for git maint.\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 5869c00..69afc84 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -223,6 +223,7 @@ cmd_add()\n \t\tmodule_clone \"$path\" \"$realrepo\" \"$reference\" || exit\n \t\t(\n \t\t\tunset GIT_DIR\n+\t\t\tunset GIT_WORK_TREE\n \t\t\tcd \"$path\" &&\n \t\t\t# ash fails to wordsplit ${branch:+-b \"$branch\"...}\n \t\t\tcase \"$branch\" in\n@@ -279,6 +280,7 @@ cmd_foreach()\n \t\t\t(\n \t\t\t\tprefix=\"$prefix$path/\"\n \t\t\t\tunset GIT_DIR\n+\t\t\t\tunset GIT_WORK_TREE\n \t\t\t\tcd \"$path\" &&\n \t\t\t\teval \"$@\" &&\n \t\t\t\tif test -n \"$recursive\"\n@@ -477,7 +479,7 @@ cmd_update()\n \t\t\t\t;;\n \t\t\tesac\n \n-\t\t\t(unset GIT_DIR; cd \"$path\" && $command \"$sha1\") ||\n+\t\t\t(unset GIT_DIR; unset GIT_WORK_TREE; cd \"$path\" && $command \"$sha1\") ||\n \t\t\tdie \"Unable to $action '$sha1' in submodule path '$path'\"\n \t\t\tsay \"Submodule path '$path': $msg '$sha1'\"\n \t\tfi\n@@ -771,6 +773,7 @@ cmd_status()\n \t\t\t(\n \t\t\t\tprefix=\"$displaypath/\"\n \t\t\t\tunset GIT_DIR\n+\t\t\t\tunset GIT_WORK_TREE\n \t\t\t\tcd \"$path\" &&\n \t\t\t\tcmd_status $orig_args\n \t\t\t) ||\n-- \n1.7.0.199.g49ef3.dirty\n"},{"id":"135360","messageId":"7vljek51t1.fsf@alter.siamese.dyndns.org","threadId":"22760","inReplyTo":"1266877015-7943-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"Re: [PATCH] submodules: ensure clean environment when operating in a submodule","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-02-22T22:43:38Z","receivedAt":"2010-02-22T22:43:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Giuseppe Bilotta <giuseppe.bilotta@gmail.com> writes:\n\n> I'm pretty confident fixing this on the submodules side is the more correct\n> approach, since otherwise even a simple\n> $ GIT_WORK_TREE=. git submodule update\n> on the command-line can fail.\n\nTrue; while I didn't bother to check what the codepaths after these\nunsetting do, I suspect you should also think about what effect it has to\nhave other GIT_* environment variables seep through to them (GIT_INDEX_FILE,\nGIT_CONFIG and GIT_OBJECT_DIRECTORY come to mind).  You would probably\nwant to have a single shell helper function to unset even if you end up\ndeciding that it is sufficient to clear GIT_DIR and GIT_WORK_TREE and\nnothing else.\n"},{"id":"135362","messageId":"cb7bb73a1002221456q6c113675i7453e0115814c99c@mail.gmail.com","threadId":"22760","inReplyTo":"7vljek51t1.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] submodules: ensure clean environment when operating in a submodule","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-02-22T22:56:39Z","receivedAt":"2010-02-22T22:56:39Z","isPatch":true,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"On Mon, Feb 22, 2010 at 11:43 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Giuseppe Bilotta <giuseppe.bilotta@gmail.com> writes:\n>\n>> I'm pretty confident fixing this on the submodules side is the more correct\n>> approach, since otherwise even a simple\n>> $ GIT_WORK_TREE=. git submodule update\n>> on the command-line can fail.\n>\n> True; while I didn't bother to check what the codepaths after these\n> unsetting do, I suspect you should also think about what effect it has to\n> have other GIT_* environment variables seep through to them (GIT_INDEX_FILE,\n> GIT_CONFIG and GIT_OBJECT_DIRECTORY come to mind).  You would probably\n> want to have a single shell helper function to unset even if you end up\n> deciding that it is sufficient to clear GIT_DIR and GIT_WORK_TREE and\n> nothing else.\n\nGood point. All GIT_* env variables should be resent when descending\ninto a submodule. Is there a way to loop over them, or do I have to do\nsomething horrible like env | grep ^GIT_ | cut -f1 -d=  to get the\nlist?\n\n\n-- \nGiuseppe \"Oblomov\" Bilotta\n"},{"id":"135363","messageId":"7vsk8s274t.fsf@alter.siamese.dyndns.org","threadId":"22760","inReplyTo":"cb7bb73a1002221456q6c113675i7453e0115814c99c@mail.gmail.com","subject":"Re: [PATCH] submodules: ensure clean environment when operating in a submodule","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-02-22T23:16:50Z","receivedAt":"2010-02-22T23:16:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Giuseppe Bilotta <giuseppe.bilotta@gmail.com> writes:\n\n> Good point. All GIT_* env variables should be resent when descending\n> into a submodule. Is there a way to loop over them, or do I have to do\n> something horrible like env | grep ^GIT_ | cut -f1 -d=  to get the\n> list?\n\nI would suggest to enumerate only what you care about explicitly, without\nconsulting the user's environment.  The user may have variables you do not\nknow about and not related to git at all.\n\nIOW, don't try to be too clever for your own good ;-)\n"},{"id":"135367","messageId":"1266881518-11213-1-git-send-email-giuseppe.bilotta@gmail.com","threadId":"22760","inReplyTo":"7vsk8s274t.fsf@alter.siamese.dyndns.org","subject":"[PATCH 1/2] shell setup: clear_local_git_env() function","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-02-22T23:31:57Z","receivedAt":"2010-02-22T23:31:57Z","isPatch":true,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Introduce an auxiliary function to clear all repo-local environment\nvariables. This should be invoked by any shell script that switches\nrepository during execution, to ensure that the environment is clean\nand that things such as the git dir and worktree are set up correctly.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n git-sh-setup.sh |    9 +++++++++\n 1 files changed, 9 insertions(+), 0 deletions(-)\n\ndiff --git a/git-sh-setup.sh b/git-sh-setup.sh\nindex 7a09566..d382879 100644\n--- a/git-sh-setup.sh\n+++ b/git-sh-setup.sh\n@@ -172,6 +172,15 @@ get_author_ident_from_commit () {\n \tLANG=C LC_ALL=C sed -ne \"$pick_author_script\"\n }\n \n+# Clear repo-local GIT_* environment variables. Useful when switching to\n+# another repository (e.g. when entering a submodule)\n+clear_local_git_env() {\n+\tunset\tGIT_DIR GIT_WORKTREE GIT_OBJECT_DIRECTORY \\\n+\t\tGIT_INDEX_FILE GIT_GRAFT_FILE GIT_CONFIG \\\n+\t\tGIT_NO_REPLACE_OBJECTS\n+\n+}\n+\n # Make sure we are in a valid repository of a vintage we understand,\n # if we require to be in a git repository.\n if test -z \"$NONGIT_OK\"\n-- \n1.7.0.200.g5ba36.dirty\n"},{"id":"135368","messageId":"1266881518-11213-2-git-send-email-giuseppe.bilotta@gmail.com","threadId":"22760","inReplyTo":"7vsk8s274t.fsf@alter.siamese.dyndns.org","subject":"[PATCH 2/2] submodules: ensure clean environment when operating in a submodule","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-02-22T23:31:58Z","receivedAt":"2010-02-22T23:31:58Z","isPatch":true,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"git-submodule used to take care of clearing GIT_DIR whenever it operated\non a submodule index or configuration, but forgot to unset GIT_WORK_TREE\nor other repo-local variables. This which would lead to failures e.g.\nwhen GIT_WORK_TREE was set.\n\nThis only happened in very unusual contexts such as operating on the\nmain worktree from outside of it, but since \"git-gui: set GIT_DIR and\nGIT_WORK_TREE after setup\" (a9fa11fe5bd5978bb) such failures could also\nbe provoked by invoking an external tool such as \"git submodule update\"\nfrom the Git Gui in a standard setup.\n\nSolve by using the newly introduced clear_local_git_env() shell function\nto ensure that all repo-local environment variables are unset.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n git-submodule.sh |   20 ++++++++++----------\n 1 files changed, 10 insertions(+), 10 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 5869c00..1ea4143 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -222,7 +222,7 @@ cmd_add()\n \n \t\tmodule_clone \"$path\" \"$realrepo\" \"$reference\" || exit\n \t\t(\n-\t\t\tunset GIT_DIR\n+\t\t\tclear_local_git_env\n \t\t\tcd \"$path\" &&\n \t\t\t# ash fails to wordsplit ${branch:+-b \"$branch\"...}\n \t\t\tcase \"$branch\" in\n@@ -278,7 +278,7 @@ cmd_foreach()\n \t\t\tname=$(module_name \"$path\")\n \t\t\t(\n \t\t\t\tprefix=\"$prefix$path/\"\n-\t\t\t\tunset GIT_DIR\n+\t\t\t\tclear_local_git_env\n \t\t\t\tcd \"$path\" &&\n \t\t\t\teval \"$@\" &&\n \t\t\t\tif test -n \"$recursive\"\n@@ -434,7 +434,7 @@ cmd_update()\n \t\t\tmodule_clone \"$path\" \"$url\" \"$reference\"|| exit\n \t\t\tsubsha1=\n \t\telse\n-\t\t\tsubsha1=$(unset GIT_DIR; cd \"$path\" &&\n+\t\t\tsubsha1=$(clear_local_git_env; cd \"$path\" &&\n \t\t\t\tgit rev-parse --verify HEAD) ||\n \t\t\tdie \"Unable to find current revision in submodule path '$path'\"\n \t\tfi\n@@ -454,7 +454,7 @@ cmd_update()\n \n \t\t\tif test -z \"$nofetch\"\n \t\t\tthen\n-\t\t\t\t(unset GIT_DIR; cd \"$path\" &&\n+\t\t\t\t(clear_local_git_env; cd \"$path\" &&\n \t\t\t\t\tgit-fetch) ||\n \t\t\t\tdie \"Unable to fetch in submodule path '$path'\"\n \t\t\tfi\n@@ -477,14 +477,14 @@ cmd_update()\n \t\t\t\t;;\n \t\t\tesac\n \n-\t\t\t(unset GIT_DIR; cd \"$path\" && $command \"$sha1\") ||\n+\t\t\t(clear_local_git_env; cd \"$path\" && $command \"$sha1\") ||\n \t\t\tdie \"Unable to $action '$sha1' in submodule path '$path'\"\n \t\t\tsay \"Submodule path '$path': $msg '$sha1'\"\n \t\tfi\n \n \t\tif test -n \"$recursive\"\n \t\tthen\n-\t\t\t(unset GIT_DIR; cd \"$path\" && cmd_update $orig_args) ||\n+\t\t\t(clear_local_git_env; cd \"$path\" && cmd_update $orig_args) ||\n \t\t\tdie \"Failed to recurse into submodule path '$path'\"\n \t\tfi\n \tdone\n@@ -492,7 +492,7 @@ cmd_update()\n \n set_name_rev () {\n \trevname=$( (\n-\t\tunset GIT_DIR\n+\t\tclear_local_git_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@@ -760,7 +760,7 @@ cmd_status()\n \t\telse\n \t\t\tif test -z \"$cached\"\n \t\t\tthen\n-\t\t\t\tsha1=$(unset GIT_DIR; cd \"$path\" && git rev-parse --verify HEAD)\n+\t\t\t\tsha1=$(clear_local_git_env; cd \"$path\" && git rev-parse --verify HEAD)\n \t\t\t\tset_name_rev \"$path\" \"$sha1\"\n \t\t\tfi\n \t\t\tsay \"+$sha1 $displaypath$revname\"\n@@ -770,7 +770,7 @@ cmd_status()\n \t\tthen\n \t\t\t(\n \t\t\t\tprefix=\"$displaypath/\"\n-\t\t\t\tunset GIT_DIR\n+\t\t\t\tclear_local_git_env\n \t\t\t\tcd \"$path\" &&\n \t\t\t\tcmd_status $orig_args\n \t\t\t) ||\n@@ -821,7 +821,7 @@ cmd_sync()\n \t\tif test -e \"$path\"/.git\n \t\tthen\n \t\t(\n-\t\t\tunset GIT_DIR\n+\t\t\tclear_local_git_env\n \t\t\tcd \"$path\"\n \t\t\tremote=$(get_default_remote)\n \t\t\tsay \"Synchronizing submodule url for '$name'\"\n-- \n1.7.0.200.g5ba36.dirty\n"},{"id":"135370","messageId":"alpine.DEB.1.00.1002230103160.3609@intel-tinevez-2-302","threadId":"22760","inReplyTo":"1266877015-7943-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"Re: [msysGit] [PATCH] submodules: ensure clean environment when operating in a submodule","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2010-02-23T00:04:00Z","receivedAt":"2010-02-23T00:04:00Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 22 Feb 2010, Giuseppe Bilotta wrote:\n\n> git-submodule takes care of clearing GIT_DIR whenever it operates\n> on a submodule index or configuration, but forgot to unset GIT_WORK_TREE\n> before operating on the submodule worktree, which would lead to failures\n> when GIT_WORK_TREE was set.\n> \n> This only happened in very unusual contexts such as operating on the\n> main worktree from outside of it, but since \"git-gui: set GIT_DIR and\n> GIT_WORK_TREE after setup\" (a9fa11fe5bd5978bb) such failures could also\n> be provoked by invoking an external tool such as \"git submodule update\"\n> from the Git GUI in a standard setup.\n> \n> Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n> ---\n\nHeiko, would you say that this patch is an elegant solution to the problem \nyou reported? If so, would you please pull it to 4msysgit.git's devel?\n\nThanks,\nDscho\n"},{"id":"135398","messageId":"4B837A73.8010406@viscovery.net","threadId":"22760","inReplyTo":"1266881518-11213-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"Re: [PATCH 1/2] shell setup: clear_local_git_env() function","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2010-02-23T06:49:23Z","receivedAt":"2010-02-23T06:49:23Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Giuseppe Bilotta schrieb:\n> +# Clear repo-local GIT_* environment variables. Useful when switching to\n> +# another repository (e.g. when entering a submodule)\n> +clear_local_git_env() {\n> +\tunset\tGIT_DIR GIT_WORKTREE GIT_OBJECT_DIRECTORY \\\n> +\t\tGIT_INDEX_FILE GIT_GRAFT_FILE GIT_CONFIG \\\n> +\t\tGIT_NO_REPLACE_OBJECTS\n\nIMO, this list should be in sync with the one you find in\nconnect.c:git_connect() around line 611. They have the same purpose.\n\n(And, BTW, a vertical list would be more readable than a mixed\nhorizontal+vertical list, IMVHO.)\n\n-- Hannes\n"},{"id":"135400","messageId":"cb7bb73a1002222355s38fda032g99623f44d6200fbc@mail.gmail.com","threadId":"22760","inReplyTo":"4B837A73.8010406@viscovery.net","subject":"Re: [PATCH 1/2] shell setup: clear_local_git_env() function","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-02-23T07:55:45Z","receivedAt":"2010-02-23T07:55:45Z","isPatch":true,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"On Tue, Feb 23, 2010 at 7:49 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:\n> Giuseppe Bilotta schrieb:\n>> +# Clear repo-local GIT_* environment variables. Useful when switching to\n>> +# another repository (e.g. when entering a submodule)\n>> +clear_local_git_env() {\n>> +     unset   GIT_DIR GIT_WORKTREE GIT_OBJECT_DIRECTORY \\\n>> +             GIT_INDEX_FILE GIT_GRAFT_FILE GIT_CONFIG \\\n>> +             GIT_NO_REPLACE_OBJECTS\n>\n> IMO, this list should be in sync with the one you find in\n> connect.c:git_connect() around line 611. They have the same purpose.\n\nAh, interesting, I was looking for such a list but only found the more\ngeneric one in cache.h\nBy comparing them it would seem they serve the same purpose, indeed. I\nnotice that the connect.c is missing GIT_CONFIG (which _must_ be unset\nfor us). I also notice that the connect.c one unsets the alternate DB;\nI had doubts about it when preparing the list in this case.\n\nI will resend a new patch to replace this one, syncing the two lists.\n\n> (And, BTW, a vertical list would be more readable than a mixed\n> horizontal+vertical list, IMVHO.)\n\nI tend to conserve vertical space, but I have no particular objection to that.\n\n-- \nGiuseppe \"Oblomov\" Bilotta\n"},{"id":"135401","messageId":"1266913829-14533-1-git-send-email-giuseppe.bilotta@gmail.com","threadId":"22760","inReplyTo":"cb7bb73a1002222355s38fda032g99623f44d6200fbc@mail.gmail.com","subject":"[PATCHv2 0/2] clear environment for submodules","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-02-23T08:30:27Z","receivedAt":"2010-02-23T08:30:27Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Second (or maybe actually third) iteration of the series to ensure that\nsubmodules work correctly when repo-local environment is set. The only\nthing changed from the previous iteration is an extra variable in\nclear_local_git_env() to bring it up in sync with the list in git_connect(),\nand also the addition of CONFIG_ENVIRONMENT in git_connect() itself.\n\nI had considered making a static list of these variables somewhere, but\nmaking it accessible to both the built-ins and shell scripts (something Ã \nla git rev-parse --local-git-env maybe?) is a little over my head at the\nmoment (not much free time to dedicate to git, sadly). Also I'm not sure\nthe extra git call needed to get the list would be worth it.\n\nGiuseppe Bilotta (2):\n  shell setup: clear_local_git_env() function\n  submodules: ensure clean environment when operating in a submodule\n\n connect.c        |    2 ++\n git-sh-setup.sh  |   15 +++++++++++++++\n git-submodule.sh |   20 ++++++++++----------\n 3 files changed, 27 insertions(+), 10 deletions(-)\n"},{"id":"135404","messageId":"1266913829-14533-2-git-send-email-giuseppe.bilotta@gmail.com","threadId":"22760","inReplyTo":"cb7bb73a1002222355s38fda032g99623f44d6200fbc@mail.gmail.com","subject":"[PATCHv2 1/2] shell setup: clear_local_git_env() function","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-02-23T08:30:28Z","receivedAt":"2010-02-23T08:30:28Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Introduce an auxiliary function to clear all repo-local environment\nvariables. This should be invoked by any shell script that switches\nrepository during execution, to ensure that the environment is clean\nand that things such as the git dir and worktree are set up correctly.\n\nThe list matches the one in git_connect(), so bring them in sync by adding\nthe missing CONFIG_ENVIRONMENT. Also add a note about the fact that they\nshould be kept that way.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n connect.c       |    2 ++\n git-sh-setup.sh |   15 +++++++++++++++\n 2 files changed, 17 insertions(+), 0 deletions(-)\n\ndiff --git a/connect.c b/connect.c\nindex 9f39038..12dd0b5 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -583,8 +583,10 @@ struct child_process *git_connect(int fd[2], const char *url_orig,\n \t}\n \telse {\n \t\t/* remove these from the environment */\n+\t\t/* see also clear_local_git_env() in git-sh-setup.sh */\n \t\tconst char *env[] = {\n \t\t\tALTERNATE_DB_ENVIRONMENT,\n+\t\t\tCONFIG_ENVIRONMENT,\n \t\t\tDB_ENVIRONMENT,\n \t\t\tGIT_DIR_ENVIRONMENT,\n \t\t\tGIT_WORK_TREE_ENVIRONMENT,\ndiff --git a/git-sh-setup.sh b/git-sh-setup.sh\nindex 7a09566..f1be832 100644\n--- a/git-sh-setup.sh\n+++ b/git-sh-setup.sh\n@@ -172,6 +172,21 @@ get_author_ident_from_commit () {\n \tLANG=C LC_ALL=C sed -ne \"$pick_author_script\"\n }\n \n+# Clear repo-local GIT_* environment variables. Useful when switching to\n+# another repository (e.g. when entering a submodule). See also the env\n+# list in git_connect()\n+clear_local_git_env() {\n+\tunset\tGIT_ALTERNATE_OBJECT_DIRECTORIES \\\n+\t\tGIT_CONFIG \\\n+\t\tGIT_DIR \\\n+\t\tGIT_GRAFT_FILE \\\n+\t\tGIT_INDEX_FILE \\\n+\t\tGIT_NO_REPLACE_OBJECTS \\\n+\t\tGIT_OBJECT_DIRECTORY \\\n+\t\tGIT_WORKTREE\n+\n+}\n+\n # Make sure we are in a valid repository of a vintage we understand,\n # if we require to be in a git repository.\n if test -z \"$NONGIT_OK\"\n-- \n1.7.0.200.g5ba36.dirty\n"},{"id":"135402","messageId":"1266913829-14533-3-git-send-email-giuseppe.bilotta@gmail.com","threadId":"22760","inReplyTo":"cb7bb73a1002222355s38fda032g99623f44d6200fbc@mail.gmail.com","subject":"[PATCHv2 2/2] submodules: ensure clean environment when operating in a submodule","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-02-23T08:30:29Z","receivedAt":"2010-02-23T08:30:29Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"git-submodule used to take care of clearing GIT_DIR whenever it operated\non a submodule index or configuration, but forgot to unset GIT_WORK_TREE\nor other repo-local variables. This which would lead to failures e.g.\nwhen GIT_WORK_TREE was set.\n\nThis only happened in very unusual contexts such as operating on the\nmain worktree from outside of it, but since \"git-gui: set GIT_DIR and\nGIT_WORK_TREE after setup\" (a9fa11fe5bd5978bb) such failures could also\nbe provoked by invoking an external tool such as \"git submodule update\"\nfrom the Git Gui in a standard setup.\n\nSolve by using the newly introduced clear_local_git_env() shell function\nto ensure that all repo-local environment variables are unset.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n git-submodule.sh |   20 ++++++++++----------\n 1 files changed, 10 insertions(+), 10 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 5869c00..1ea4143 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -222,7 +222,7 @@ cmd_add()\n \n \t\tmodule_clone \"$path\" \"$realrepo\" \"$reference\" || exit\n \t\t(\n-\t\t\tunset GIT_DIR\n+\t\t\tclear_local_git_env\n \t\t\tcd \"$path\" &&\n \t\t\t# ash fails to wordsplit ${branch:+-b \"$branch\"...}\n \t\t\tcase \"$branch\" in\n@@ -278,7 +278,7 @@ cmd_foreach()\n \t\t\tname=$(module_name \"$path\")\n \t\t\t(\n \t\t\t\tprefix=\"$prefix$path/\"\n-\t\t\t\tunset GIT_DIR\n+\t\t\t\tclear_local_git_env\n \t\t\t\tcd \"$path\" &&\n \t\t\t\teval \"$@\" &&\n \t\t\t\tif test -n \"$recursive\"\n@@ -434,7 +434,7 @@ cmd_update()\n \t\t\tmodule_clone \"$path\" \"$url\" \"$reference\"|| exit\n \t\t\tsubsha1=\n \t\telse\n-\t\t\tsubsha1=$(unset GIT_DIR; cd \"$path\" &&\n+\t\t\tsubsha1=$(clear_local_git_env; cd \"$path\" &&\n \t\t\t\tgit rev-parse --verify HEAD) ||\n \t\t\tdie \"Unable to find current revision in submodule path '$path'\"\n \t\tfi\n@@ -454,7 +454,7 @@ cmd_update()\n \n \t\t\tif test -z \"$nofetch\"\n \t\t\tthen\n-\t\t\t\t(unset GIT_DIR; cd \"$path\" &&\n+\t\t\t\t(clear_local_git_env; cd \"$path\" &&\n \t\t\t\t\tgit-fetch) ||\n \t\t\t\tdie \"Unable to fetch in submodule path '$path'\"\n \t\t\tfi\n@@ -477,14 +477,14 @@ cmd_update()\n \t\t\t\t;;\n \t\t\tesac\n \n-\t\t\t(unset GIT_DIR; cd \"$path\" && $command \"$sha1\") ||\n+\t\t\t(clear_local_git_env; cd \"$path\" && $command \"$sha1\") ||\n \t\t\tdie \"Unable to $action '$sha1' in submodule path '$path'\"\n \t\t\tsay \"Submodule path '$path': $msg '$sha1'\"\n \t\tfi\n \n \t\tif test -n \"$recursive\"\n \t\tthen\n-\t\t\t(unset GIT_DIR; cd \"$path\" && cmd_update $orig_args) ||\n+\t\t\t(clear_local_git_env; cd \"$path\" && cmd_update $orig_args) ||\n \t\t\tdie \"Failed to recurse into submodule path '$path'\"\n \t\tfi\n \tdone\n@@ -492,7 +492,7 @@ cmd_update()\n \n set_name_rev () {\n \trevname=$( (\n-\t\tunset GIT_DIR\n+\t\tclear_local_git_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@@ -760,7 +760,7 @@ cmd_status()\n \t\telse\n \t\t\tif test -z \"$cached\"\n \t\t\tthen\n-\t\t\t\tsha1=$(unset GIT_DIR; cd \"$path\" && git rev-parse --verify HEAD)\n+\t\t\t\tsha1=$(clear_local_git_env; cd \"$path\" && git rev-parse --verify HEAD)\n \t\t\t\tset_name_rev \"$path\" \"$sha1\"\n \t\t\tfi\n \t\t\tsay \"+$sha1 $displaypath$revname\"\n@@ -770,7 +770,7 @@ cmd_status()\n \t\tthen\n \t\t\t(\n \t\t\t\tprefix=\"$displaypath/\"\n-\t\t\t\tunset GIT_DIR\n+\t\t\t\tclear_local_git_env\n \t\t\t\tcd \"$path\" &&\n \t\t\t\tcmd_status $orig_args\n \t\t\t) ||\n@@ -821,7 +821,7 @@ cmd_sync()\n \t\tif test -e \"$path\"/.git\n \t\tthen\n \t\t(\n-\t\t\tunset GIT_DIR\n+\t\t\tclear_local_git_env\n \t\t\tcd \"$path\"\n \t\t\tremote=$(get_default_remote)\n \t\t\tsay \"Synchronizing submodule url for '$name'\"\n-- \n1.7.0.200.g5ba36.dirty\n"},{"id":"135457","messageId":"4B8439B4.9030605@web.de","threadId":"22760","inReplyTo":"1266913829-14533-2-git-send-email-giuseppe.bilotta@gmail.com","subject":"Re: [PATCHv2 1/2] shell setup: clear_local_git_env() function","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2010-02-23T20:25:24Z","receivedAt":"2010-02-23T20:25:24Z","isPatch":false,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Am 23.02.2010 09:30, schrieb Giuseppe Bilotta:\n> diff --git a/git-sh-setup.sh b/git-sh-setup.sh\n> index 7a09566..f1be832 100644\n> --- a/git-sh-setup.sh\n> +++ b/git-sh-setup.sh\n> @@ -172,6 +172,21 @@ get_author_ident_from_commit () {\n>  \tLANG=C LC_ALL=C sed -ne \"$pick_author_script\"\n>  }\n>  \n> +# Clear repo-local GIT_* environment variables. Useful when switching to\n> +# another repository (e.g. when entering a submodule). See also the env\n> +# list in git_connect()\n> +clear_local_git_env() {\n> +\tunset\tGIT_ALTERNATE_OBJECT_DIRECTORIES \\\n> +\t\tGIT_CONFIG \\\n> +\t\tGIT_DIR \\\n> +\t\tGIT_GRAFT_FILE \\\n> +\t\tGIT_INDEX_FILE \\\n> +\t\tGIT_NO_REPLACE_OBJECTS \\\n> +\t\tGIT_OBJECT_DIRECTORY \\\n> +\t\tGIT_WORKTREE\n\nShouldn't that last one be GIT_WORK_TREE?\n\n\n> +\n> +}\n> +\n>  # Make sure we are in a valid repository of a vintage we understand,\n>  # if we require to be in a git repository.\n>  if test -z \"$NONGIT_OK\"\n"},{"id":"135465","messageId":"20100223210751.GA10932@book.hvoigt.net","threadId":"22760","inReplyTo":"alpine.DEB.1.00.1002230103160.3609@intel-tinevez-2-302","subject":"Re: Re: [msysGit] [PATCH] submodules: ensure clean environment when operating in a submodule","fromName":"Heiko Voigt","fromEmail":"hvoigt@hvoigt.net","sentAt":"2010-02-23T21:07:53Z","receivedAt":"2010-02-23T21:07:53Z","isPatch":true,"sender":{"key":"hvoigt@hvoigt.net","avatar":"https://avatars.githubusercontent.com/u/184958?v=4"},"body":"On Tue, Feb 23, 2010 at 01:04:00AM +0100, Johannes Schindelin wrote:\n> Hi,\n> \n> On Mon, 22 Feb 2010, Giuseppe Bilotta wrote:\n> \n> > git-submodule takes care of clearing GIT_DIR whenever it operates\n> > on a submodule index or configuration, but forgot to unset GIT_WORK_TREE\n> > before operating on the submodule worktree, which would lead to failures\n> > when GIT_WORK_TREE was set.\n> > \n> > This only happened in very unusual contexts such as operating on the\n> > main worktree from outside of it, but since \"git-gui: set GIT_DIR and\n> > GIT_WORK_TREE after setup\" (a9fa11fe5bd5978bb) such failures could also\n> > be provoked by invoking an external tool such as \"git submodule update\"\n> > from the Git GUI in a standard setup.\n> > \n> > Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n> > ---\n> \n> Heiko, would you say that this patch is an elegant solution to the problem \n> you reported? If so, would you please pull it to 4msysgit.git's devel?\n\nI would like to leave the patch cooking a little more. For example see\nthe objection of Jens[1]. Just to be sure that we do not pull in other\nissues with this. Sorry I do not have the time for extensive testing\ncurrently. So my suggestion would be to leave msysgit in the current\nstate as I did not discover any downsides with just the revert with my\ncurrent users tests.\n\nAs far as I understand the patch fixes issues when submodules itself\ncontain submodules and it seems that not many users are doing this\ncurrently. Once everybody is happy (and tried) the patches I do not have\nany objections to pushing it into devel.\n\nWhat do you think?\n\ncheers Heiko\n\n[1] http://groups.google.com/group/msysgit/msg/481e252ba4f49ede\n"},{"id":"135471","messageId":"alpine.DEB.1.00.1002232246560.3980@intel-tinevez-2-302","threadId":"22760","inReplyTo":"20100223210751.GA10932@book.hvoigt.net","subject":"Re: Re: [msysGit] [PATCH] submodules: ensure clean environment when operating in a submodule","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2010-02-23T21:47:18Z","receivedAt":"2010-02-23T21:47:18Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 23 Feb 2010, Heiko Voigt wrote:\n\n> On Tue, Feb 23, 2010 at 01:04:00AM +0100, Johannes Schindelin wrote:\n> \n> > On Mon, 22 Feb 2010, Giuseppe Bilotta wrote:\n> > \n> > > git-submodule takes care of clearing GIT_DIR whenever it operates on \n> > > a submodule index or configuration, but forgot to unset \n> > > GIT_WORK_TREE before operating on the submodule worktree, which \n> > > would lead to failures when GIT_WORK_TREE was set.\n> > > \n> > > This only happened in very unusual contexts such as operating on the \n> > > main worktree from outside of it, but since \"git-gui: set GIT_DIR \n> > > and GIT_WORK_TREE after setup\" (a9fa11fe5bd5978bb) such failures \n> > > could also be provoked by invoking an external tool such as \"git \n> > > submodule update\" from the Git GUI in a standard setup.\n> > \n> > Heiko, would you say that this patch is an elegant solution to the \n> > problem you reported? If so, would you please pull it to \n> > 4msysgit.git's devel?\n> \n> I would like to leave the patch cooking a little more.\n\nYes, that matches my feeling.\n\nThanks,\nDscho\n"}]}