aboutsummaryrefslogtreecommitdiff
path: root/t/t0001-init.sh
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2015-12-20 14:50:19 +0700
committerJunio C Hamano <gitster@pobox.com>2015-12-22 13:40:32 -0800
commit57ea7123c86771f47f34e7d92d1822d8b429897a (patch)
tree1e9769ae51c20a2136de3f9656f926079254df2e /t/t0001-init.sh
parent86d26f240fcb4f287258ad459efc2b5e30e60cfd (diff)
downloadgit-57ea7123c86771f47f34e7d92d1822d8b429897a.tar.gz
git-57ea7123c86771f47f34e7d92d1822d8b429897a.tar.xz
git.c: make sure we do not leak GIT_* to alias scripts
The unfortunate commit d95138e (setup: set env $GIT_WORK_TREE when work tree is set, like $GIT_DIR - 2015-06-26) exposes another problem, besides git-clone that's described in the previous commit. If GIT_WORK_TREE (or even GIT_DIR) is exported to an alias script, it may mislead git commands in the script where the repo is. Granted, most scripts work on the repo where the alias is summoned from. But nowhere do we forbid the script to visit another repository. The revert of d95138e in the previous commit is sufficient as a fix. However, to protect us from accidentally leaking GIT_* environment variables again, we restore certain sensitive env before calling the external script. GIT_PREFIX is let through because there's another setup side effect that we simply accepted so far: current working directory is moved. Maybe in future we can introduce a new alias format that guarantees no cwd move, then we can unexport GIT_PREFIX. Reported-by: Gabriel Ganne <gabriel.ganne@gmail.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t0001-init.sh')
-rwxr-xr-xt/t0001-init.sh17
1 files changed, 17 insertions, 0 deletions
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 7de8d85ee..f7c00f6b1 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -87,6 +87,23 @@ test_expect_success 'plain nested in bare through aliased command' '
check_config bare-ancestor-aliased.git/plain-nested/.git false unset
'
+test_expect_success 'No extra GIT_* on alias scripts' '
+ (
+ env | sed -ne "/^GIT_/s/=.*//p" &&
+ echo GIT_PREFIX && # setup.c
+ echo GIT_TEXTDOMAINDIR # wrapper-for-bin.sh
+ ) | sort | uniq >expected &&
+ cat <<-\EOF >script &&
+ #!/bin/sh
+ env | sed -ne "/^GIT_/s/=.*//p" | sort >actual
+ exit 0
+ EOF
+ chmod 755 script &&
+ git config alias.script \!./script &&
+ ( mkdir sub && cd sub && git script ) &&
+ test_cmp expected actual
+'
+
test_expect_success 'plain with GIT_WORK_TREE' '
mkdir plain-wt &&
test_must_fail env GIT_WORK_TREE="$(pwd)/plain-wt" git init plain-wt