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

[RFC/PATCH] handle_alias: provide GIT_CWD to !alias

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Apr 13, 2011, 13:05 UTC
Message-ID
<e8c9aa9160f922f728d56387e5e86eb50220774f.1302699792.git.git@drmicha.warpmail.net>
In-Reply-To
<4DA59B27.50506@ge.infn.it>

Provide an environment variable GIT_CWD which contains the subdirectory from which a !alias was called since these cd to the to level directory before they are executed.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
RFC for lack of tests and doc.

I would say this is something realistic and useful which can be done now, no matter how our efforts with !(top) and the like go.

 git.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/git.c b/git.c
index ef598c3..c8b9189 100644
--- a/git.c
+++ b/git.c
@@ -179,6 +179,8 @@ static int handle_alias(int *argcp, const char ***argv)
 		if (alias_string[0] == '!') {
 			const char **alias_argv;
 			int argc = *argcp, i;
+			struct strbuf sb = STRBUF_INIT;
+			const char *env[2];
 
 			commit_pager_choice();
 
@@ -189,7 +191,13 @@ static int handle_alias(int *argcp, const char ***argv)
 				alias_argv[i] = (*argv)[i];
 			alias_argv[argc] = NULL;
 
-			ret = run_command_v_opt(alias_argv, RUN_USING_SHELL);
+			strbuf_addstr(&sb, "GIT_CWD=");
+			if (subdir)
+				strbuf_addstr(&sb, subdir);
+			env[0] = sb.buf;
+			env[1] = NULL;
+			ret = run_command_v_opt_cd_env(alias_argv, RUN_USING_SHELL, NULL, env);
+			strbuf_release(&sb);
 			if (ret >= 0)   /* normal exit */
 				exit(ret);
 
-- 
1.7.5.rc0.365.g23929a
Next: Nguyen Thai Ngoc Duy
Message 1 of 12 in “handle_alias: provide GIT_CWD to !alias”
  1. handle_alias: provide GIT_CWD to !aliasMichael J Gruber, Apr 13, 2011
  2. Nguyen Thai Ngoc DuyApr 13, 2011
  3. Michael J GruberApr 13, 2011
  4. Nguyen Thai Ngoc DuyApr 13, 2011
  5. Junio C HamanoApr 26, 2011
  6. Michael J GruberApr 27, 2011
  7. Nguyen Thai Ngoc DuyApr 27, 2011
  8. Michael J GruberApr 27, 2011
  9. 1/2 t1020: test !alias in subdirectoryMichael J Gruber, Apr 27, 2011
  10. 2/2 handle_alias: provide GIT_PREFIX to !aliasMichael J Gruber, Apr 27, 2011
  11. Nguyen Thai Ngoc DuyApr 27, 2011
  12. Michael J GruberApr 27, 2011

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.