{"thread":{"id":"38328","subject":"[PATCH] git.c: prevent change of environment variables","startedAt":"2015-01-10T12:53:36Z","lastAt":"2015-01-10T18:07:46Z","messageCount":2,"participants":["Alexander Kuleshov"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"254528","messageId":"1420894416-22615-1-git-send-email-kuleshovmail@gmail.com","threadId":"38328","inReplyTo":null,"subject":"[PATCH] git.c: prevent change of environment variables","fromName":"Alexander Kuleshov","fromEmail":"kuleshovmail@gmail.com","sentAt":"2015-01-10T12:53:36Z","receivedAt":"2015-01-10T12:53:36Z","isPatch":true,"sender":{"key":"kuleshovmail@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2699235?v=4"},"body":"We can't change environment variables in aliases which doesn't start with '!'\n\n* 'git --exec-path=path' changes $GIT_EXEC_PATH variable in\ngit_set_argv_exec_path\n\n* 'git -p/--paginate' sets 'use_pager' to 1 and commit_pager_choice\nwill change $GIT_PAGER_IN_USE variable in setup_pager(void) from pager.c\n\n* 'git -c' calls git_config_push_parameter which will change\n$GIT_CONFIG_PARAMETERS variable\n\nSigned-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>\n---\n git.c | 9 ++++++++-\n 1 file changed, 8 insertions(+), 1 deletion(-)\n\ndiff --git a/git.c b/git.c\nindex c9bec99..3e87f05 100644\n--- a/git.c\n+++ b/git.c\n@@ -89,8 +89,11 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)\n \t\t * Check remaining flags.\n \t\t */\n \t\tif (skip_prefix(cmd, \"--exec-path\", &cmd)) {\n-\t\t\tif (*cmd == '=')\n+\t\t\tif (*cmd == '=') {\n \t\t\t\tgit_set_argv_exec_path(cmd + 1);\n+\t\t\t\tif (envchanged)\n+\t\t\t\t\t*envchanged = 1;\n+\t\t\t}\n \t\t\telse {\n \t\t\t\tputs(git_exec_path());\n \t\t\t\texit(0);\n@@ -106,6 +109,8 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)\n \t\t\texit(0);\n \t\t} else if (!strcmp(cmd, \"-p\") || !strcmp(cmd, \"--paginate\")) {\n \t\t\tuse_pager = 1;\n+\t\t\tif (envchanged)\n+\t\t\t\t*envchanged = 1;\n \t\t} else if (!strcmp(cmd, \"--no-pager\")) {\n \t\t\tuse_pager = 0;\n \t\t\tif (envchanged)\n@@ -171,6 +176,8 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)\n \t\t\t\tusage(git_usage_string);\n \t\t\t}\n \t\t\tgit_config_push_parameter((*argv)[1]);\n+\t\t\tif (envchanged)\n+\t\t\t\t*envchanged = 1;\n \t\t\t(*argv)++;\n \t\t\t(*argc)--;\n \t\t} else if (!strcmp(cmd, \"--literal-pathspecs\")) {\n-- \n2.2.1.531.g5addc96.dirty\n"},{"id":"254534","messageId":"CANCZXo56nqzDw6CFUNXfRg+bjq2Z9TdzhZ6uZcEeu9zZLExnQQ@mail.gmail.com","threadId":"38328","inReplyTo":"1420894416-22615-1-git-send-email-kuleshovmail@gmail.com","subject":"Re: [PATCH] git.c: prevent change of environment variables","fromName":"Alexander Kuleshov","fromEmail":"kuleshovmail@gmail.com","sentAt":"2015-01-10T18:07:46Z","receivedAt":"2015-01-10T18:07:46Z","isPatch":true,"sender":{"key":"kuleshovmail@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2699235?v=4"},"body":"There is aliasing of git -c .... in t1300-repo-config.sh, but I see:\n\ndie(\"alias '%s' changes environment variables\\n\"\n      \"You can use '!git' in the alias to do this.\",\n      alias_command);\n\nat git.c, how to be here?\n\nThank you.\n\n2015-01-10 18:53 GMT+06:00 Alexander Kuleshov <kuleshovmail@gmail.com>:\n> We can't change environment variables in aliases which doesn't start with '!'\n>\n> * 'git --exec-path=path' changes $GIT_EXEC_PATH variable in\n> git_set_argv_exec_path\n>\n> * 'git -p/--paginate' sets 'use_pager' to 1 and commit_pager_choice\n> will change $GIT_PAGER_IN_USE variable in setup_pager(void) from pager.c\n>\n> * 'git -c' calls git_config_push_parameter which will change\n> $GIT_CONFIG_PARAMETERS variable\n>\n> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>\n> ---\n>  git.c | 9 ++++++++-\n>  1 file changed, 8 insertions(+), 1 deletion(-)\n>\n> diff --git a/git.c b/git.c\n> index c9bec99..3e87f05 100644\n> --- a/git.c\n> +++ b/git.c\n> @@ -89,8 +89,11 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)\n>                  * Check remaining flags.\n>                  */\n>                 if (skip_prefix(cmd, \"--exec-path\", &cmd)) {\n> -                       if (*cmd == '=')\n> +                       if (*cmd == '=') {\n>                                 git_set_argv_exec_path(cmd + 1);\n> +                               if (envchanged)\n> +                                       *envchanged = 1;\n> +                       }\n>                         else {\n>                                 puts(git_exec_path());\n>                                 exit(0);\n> @@ -106,6 +109,8 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)\n>                         exit(0);\n>                 } else if (!strcmp(cmd, \"-p\") || !strcmp(cmd, \"--paginate\")) {\n>                         use_pager = 1;\n> +                       if (envchanged)\n> +                               *envchanged = 1;\n>                 } else if (!strcmp(cmd, \"--no-pager\")) {\n>                         use_pager = 0;\n>                         if (envchanged)\n> @@ -171,6 +176,8 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)\n>                                 usage(git_usage_string);\n>                         }\n>                         git_config_push_parameter((*argv)[1]);\n> +                       if (envchanged)\n> +                               *envchanged = 1;\n>                         (*argv)++;\n>                         (*argc)--;\n>                 } else if (!strcmp(cmd, \"--literal-pathspecs\")) {\n> --\n> 2.2.1.531.g5addc96.dirty\n>\n\n\n\n-- \n_________________________\n0xAX\n"}]}