{"thread":{"id":"47086","subject":"[PATCH] sequencer: pass absolute GIT_DIR to exec commands","startedAt":"2017-10-31T23:07:40Z","lastAt":"2017-11-01T21:15:10Z","messageCount":2,"participants":["Jacob Keller","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"331525","messageId":"20171031230733.18949-1-jacob.e.keller@intel.com","threadId":"47086","inReplyTo":null,"subject":"[PATCH] sequencer: pass absolute GIT_DIR to exec commands","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2017-10-31T23:07:33Z","receivedAt":"2017-10-31T23:07:40Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\nWhen we replaced the old shell script based interactive rebase in\ncommmit 18633e1a22a6 (\"rebase -i: use the rebase--helper builtin\",\n2017-02-09) we introduced a regression of functionality in that the\nGIT_DIR would be sent to the environment of the exec command as-is.\n\nThis generally meant that it would be passed as \"GIT_DIR=.git\", which\ncauses problems for any exec command that wants to run git commands in\na subdirectory.\n\nThis isn't a very large regression, since it is not that likely that the\nexec command will run a git command, and even less likely that it will\nneed to do so in a subdir. This regression was discovered by a build\nsystem which uses git-describe to find the current version of the build\nsystem, and happened to do so from the src/ sub directory of the\nproject.\n\nFix this by passing in the absolute path of the git directory into the\nchild environment.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n sequencer.c                   |  7 ++++++-\n t/t3404-rebase-interactive.sh | 11 +++++++++++\n 2 files changed, 17 insertions(+), 1 deletion(-)\n\ndiff --git a/sequencer.c b/sequencer.c\nindex f2a10cc4f24c..332a383b037d 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -1862,12 +1862,15 @@ static int error_failed_squash(struct commit *commit,\n \n static int do_exec(const char *command_line)\n {\n+\tstruct argv_array child_env = ARGV_ARRAY_INIT;\n \tconst char *child_argv[] = { NULL, NULL };\n \tint dirty, status;\n \n \tfprintf(stderr, \"Executing: %s\\n\", command_line);\n \tchild_argv[0] = command_line;\n-\tstatus = run_command_v_opt(child_argv, RUN_USING_SHELL);\n+\targv_array_pushf(&child_env, \"GIT_DIR=%s\", absolute_path(get_git_dir()));\n+\tstatus = run_command_v_opt_cd_env(child_argv, RUN_USING_SHELL, NULL,\n+\t\t\t\t\t  child_env.argv);\n \n \t/* force re-reading of the cache */\n \tif (discard_cache() < 0 || read_cache() < 0)\n@@ -1897,6 +1900,8 @@ static int do_exec(const char *command_line)\n \t\tstatus = 1;\n \t}\n \n+\targv_array_clear(&child_env);\n+\n \treturn status;\n }\n \ndiff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh\nindex 3704dbb2ecf6..6a82d1ed876d 100755\n--- a/t/t3404-rebase-interactive.sh\n+++ b/t/t3404-rebase-interactive.sh\n@@ -108,6 +108,17 @@ test_expect_success 'rebase -i with the exec command runs from tree root' '\n \trm -fr subdir\n '\n \n+test_expect_success 'rebase -i with exec allows git commands in subdirs' '\n+\ttest_when_finished \"rm -rf subdir\" &&\n+\ttest_when_finished \"git rebase --abort ||:\" &&\n+\tgit checkout master &&\n+\tmkdir subdir && (cd subdir &&\n+\tset_fake_editor &&\n+\tFAKE_LINES=\"1 exec_cd_subdir_&&_git_rev-parse_--is-inside-work-tree\" \\\n+\t\tgit rebase -i HEAD^\n+\t)\n+'\n+\n test_expect_success 'rebase -i with the exec command checks tree cleanness' '\n \tgit checkout master &&\n \tset_fake_editor &&\n-- \n2.11.1.4.gad8c7cd\n\n"},{"id":"331611","messageId":"alpine.DEB.2.21.1.1711012214220.6482@virtualbox","threadId":"47086","inReplyTo":"20171031230733.18949-1-jacob.e.keller@intel.com","subject":"Re: [PATCH] sequencer: pass absolute GIT_DIR to exec commands","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2017-11-01T21:14:39Z","receivedAt":"2017-11-01T21:15:10Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Jake,\n\nOn Tue, 31 Oct 2017, Jacob Keller wrote:\n\n> From: Jacob Keller <jacob.keller@gmail.com>\n> \n> When we replaced the old shell script based interactive rebase in\n> commmit 18633e1a22a6 (\"rebase -i: use the rebase--helper builtin\",\n> 2017-02-09) we introduced a regression of functionality in that the\n> GIT_DIR would be sent to the environment of the exec command as-is.\n> \n> This generally meant that it would be passed as \"GIT_DIR=.git\", which\n> causes problems for any exec command that wants to run git commands in\n> a subdirectory.\n> \n> This isn't a very large regression, since it is not that likely that the\n> exec command will run a git command, and even less likely that it will\n> need to do so in a subdir. This regression was discovered by a build\n> system which uses git-describe to find the current version of the build\n> system, and happened to do so from the src/ sub directory of the\n> project.\n> \n> Fix this by passing in the absolute path of the git directory into the\n> child environment.\n> \n> Signed-off-by: Jacob Keller <jacob.keller@gmail.com>\n\nACK,\nDscho\n"}]}