From 1f5d271f5e8f7b1e2a5b296ff43ca4087eb08244 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Wed, 25 May 2011 20:37:12 -0700 Subject: setup: Provide GIT_PREFIX to built-ins GIT_PREFIX was added in 7cf16a14f5c070f7b14cf28023769450133172ae so that aliases can know the directory from which a !alias was called. Knowing the prefix relative to the root is helpful in other programs so export it to built-ins as well. Helped-by: Michael J Gruber Signed-off-by: David Aguilar Signed-off-by: Junio C Hamano --- t/t1020-subdirectory.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 't') diff --git a/t/t1020-subdirectory.sh b/t/t1020-subdirectory.sh index ddc3921ac6..3c7448026d 100755 --- a/t/t1020-subdirectory.sh +++ b/t/t1020-subdirectory.sh @@ -139,6 +139,22 @@ test_expect_success 'GIT_PREFIX for !alias' ' test_cmp expect actual ' +test_expect_success 'GIT_PREFIX for built-ins' ' + # Use GIT_EXTERNAL_DIFF to test that the "diff" built-in + # receives the GIT_PREFIX variable. + printf "dir/" >expect && + printf "#!/bin/sh\n" >diff && + printf "printf \"\$GIT_PREFIX\"" >>diff && + chmod +x diff && + ( + cd dir && + printf "change" >two && + env GIT_EXTERNAL_DIFF=./diff git diff >../actual + git checkout -- two + ) && + test_cmp expect actual +' + test_expect_success 'no file/rev ambiguity check inside .git' ' git commit -a -m 1 && ( -- cgit v1.2.1 From c35ec8c901a2391c4652ab1acdff04c9d67b1543 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Thu, 2 Jun 2011 02:26:25 -0700 Subject: t/t7503-pre-commit-hook.sh: Add GIT_PREFIX tests Ensure that the pre-commit hook has access to GIT_PREFIX. Signed-off-by: David Aguilar Signed-off-by: Junio C Hamano --- t/t7503-pre-commit-hook.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 't') diff --git a/t/t7503-pre-commit-hook.sh b/t/t7503-pre-commit-hook.sh index 8528f64c8d..ee7f0cd459 100755 --- a/t/t7503-pre-commit-hook.sh +++ b/t/t7503-pre-commit-hook.sh @@ -84,5 +84,38 @@ test_expect_success POSIXPERM '--no-verify with non-executable hook' ' git commit --no-verify -m "more content" ' +chmod +x "$HOOK" + +# a hook that checks $GIT_PREFIX and succeeds inside the +# success/ subdirectory only +cat > "$HOOK" <> file && + git add file && + mkdir success && + ( + cd success && + git commit -m "hook requires GIT_PREFIX = success/" + ) && + rmdir success +' + +test_expect_success 'with failing hook requiring GIT_PREFIX' ' + + echo "more content" >> file && + git add file && + mkdir fail && + ( + cd fail && + test_must_fail git commit -m "hook must fail" + ) && + rmdir fail && + git checkout -- file +' test_done -- cgit v1.2.1