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

[PATCHv2 1/2] shell setup: clear_local_git_env() function

From
Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Date
Feb 23, 2010, 08:30 UTC
Message-ID
<1266913829-14533-2-git-send-email-giuseppe.bilotta@gmail.com>
In-Reply-To
<cb7bb73a1002222355s38fda032g99623f44d6200fbc@mail.gmail.com>

Introduce an auxiliary function to clear all repo-local environment variables. This should be invoked by any shell script that switches repository during execution, to ensure that the environment is clean and that things such as the git dir and worktree are set up correctly.

The list matches the one in git_connect(), so bring them in sync by adding the missing CONFIG_ENVIRONMENT. Also add a note about the fact that they should be kept that way.

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
 connect.c       |    2 ++
 git-sh-setup.sh |   15 +++++++++++++++
 2 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/connect.c b/connect.c
index 9f39038..12dd0b5 100644
--- a/connect.c
+++ b/connect.c
@@ -583,8 +583,10 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
 	}
 	else {
 		/* remove these from the environment */
+		/* see also clear_local_git_env() in git-sh-setup.sh */
 		const char *env[] = {
 			ALTERNATE_DB_ENVIRONMENT,
+			CONFIG_ENVIRONMENT,
 			DB_ENVIRONMENT,
 			GIT_DIR_ENVIRONMENT,
 			GIT_WORK_TREE_ENVIRONMENT,
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index 7a09566..f1be832 100644
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -172,6 +172,21 @@ get_author_ident_from_commit () {
 	LANG=C LC_ALL=C sed -ne "$pick_author_script"
 }
 
+# Clear repo-local GIT_* environment variables. Useful when switching to
+# another repository (e.g. when entering a submodule). See also the env
+# list in git_connect()
+clear_local_git_env() {
+	unset	GIT_ALTERNATE_OBJECT_DIRECTORIES \
+		GIT_CONFIG \
+		GIT_DIR \
+		GIT_GRAFT_FILE \
+		GIT_INDEX_FILE \
+		GIT_NO_REPLACE_OBJECTS \
+		GIT_OBJECT_DIRECTORY \
+		GIT_WORKTREE
+
+}
+
 # Make sure we are in a valid repository of a vintage we understand,
 # if we require to be in a git repository.
 if test -z "$NONGIT_OK"
-- 
1.7.0.200.g5ba36.dirty
Previous: Giuseppe BilottaNext: Jens Lehmann
Message 9 of 15 in “submodules: ensure clean environment when operating in a submodule”
  1. submodules: ensure clean environment when operating in a submoduleGiuseppe Bilotta, Feb 22, 2010
  2. Junio C HamanoFeb 22, 2010
  3. Giuseppe BilottaFeb 22, 2010
  4. Junio C HamanoFeb 22, 2010
  5. 1/2 shell setup: clear_local_git_env() functionGiuseppe Bilotta, Feb 22, 2010
  6. Johannes SixtFeb 23, 2010
  7. Giuseppe BilottaFeb 23, 2010
  8. 0/2 clear environment for submodulesGiuseppe Bilotta, Feb 23, 2010
  9. 1/2 shell setup: clear_local_git_env() functionGiuseppe Bilotta, Feb 23, 2010
  10. Jens LehmannFeb 23, 2010
  11. 2/2 submodules: ensure clean environment when operating in a submoduleGiuseppe Bilotta, Feb 23, 2010
  12. 2/2 submodules: ensure clean environment when operating in a submoduleGiuseppe Bilotta, Feb 22, 2010
  13. Johannes SchindelinFeb 23, 2010
  14. Heiko VoigtFeb 23, 2010
  15. Johannes SchindelinFeb 23, 2010

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

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