git.c: make sure we do not leak GIT_* to alias scripts
[gitweb.git] / git.c
diff --git a/git.c b/git.c
index 77ef23ece0e9327dc6dc80659bd4165a9f2275d9..98d441220a29f2b660a0bb37412ff1ec98453412 100644 (file)
--- a/git.c
+++ b/git.c
@@ -41,13 +41,16 @@ static void save_env_before_alias(void)
        }
 }
 
-static void restore_env(void)
+static void restore_env(int external_alias)
 {
        int i;
-       if (orig_cwd && chdir(orig_cwd))
+       if (!external_alias && orig_cwd && chdir(orig_cwd))
                die_errno("could not move to %s", orig_cwd);
        free(orig_cwd);
        for (i = 0; i < ARRAY_SIZE(env_names); i++) {
+               if (external_alias &&
+                   !strcmp(env_names[i], GIT_PREFIX_ENVIRONMENT))
+                       continue;
                if (orig_env[i])
                        setenv(env_names[i], orig_env[i], 1);
                else
@@ -243,6 +246,7 @@ static int handle_alias(int *argcp, const char ***argv)
                        int argc = *argcp, i;
 
                        commit_pager_choice();
+                       restore_env(1);
 
                        /* build alias_argv */
                        alias_argv = xmalloc(sizeof(*alias_argv) * (argc + 1));
@@ -291,7 +295,7 @@ static int handle_alias(int *argcp, const char ***argv)
                ret = 1;
        }
 
-       restore_env();
+       restore_env(0);
 
        errno = saved_errno;