From 04861982e553289c923b2f9ef829ef33206c9bc4 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 11 Mar 2012 03:51:32 -0700 Subject: t7503: does pre-commit-hook learn authorship? When "--author" option is used to lie the authorship to "git commit" command, hooks should learn the author name and email just like when GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL environment variables are used to lie the authorship. Test this. Signed-off-by: Junio C Hamano --- t/t7503-pre-commit-hook.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 't/t7503-pre-commit-hook.sh') diff --git a/t/t7503-pre-commit-hook.sh b/t/t7503-pre-commit-hook.sh index ee7f0cd459..aa294ea428 100755 --- a/t/t7503-pre-commit-hook.sh +++ b/t/t7503-pre-commit-hook.sh @@ -118,4 +118,22 @@ test_expect_success 'with failing hook requiring GIT_PREFIX' ' git checkout -- file ' +test_expect_failure 'check the author in hook' ' + write_script "$HOOK" <<-\EOF && + test "$GIT_AUTHOR_NAME" = "New Author" && + test "$GIT_AUTHOR_EMAIL" = "newauthor@example.com" + EOF + test_must_fail git commit --allow-empty -m "by a.u.thor" && + ( + GIT_AUTHOR_NAME="New Author" && + GIT_AUTHOR_EMAIL="newauthor@example.com" && + export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL && + git commit --allow-empty -m "by new.author via env" && + git show -s + ) && + git commit --author="New Author " \ + --allow-empty -m "by new.author via command line" && + git show -s +' + test_done -- cgit v1.2.3 From 7dfe8ad6006c105989e4e8cfb196aa4ecda3c21d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 11 Mar 2012 03:12:10 -0700 Subject: commit: pass author/committer info to hooks When lying the author name via GIT_AUTHOR_NAME environment variable to "git commit", the hooks run by the command saw it and could act on the name that will be recorded in the final commit. When the user uses the "--author" option from the command line, the command should give the same information to the hook, and back when "git command" was a scripted Porcelain, it did set the environment variable and hooks can learn the author name from it. However, when the command was reimplemented in C, the rewritten code was not very faithful to the original, and hooks stopped getting the authorship information given with "--author". Fix this by exporting the necessary environment variables. Signed-off-by: Junio C Hamano --- t/t7503-pre-commit-hook.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/t7503-pre-commit-hook.sh') diff --git a/t/t7503-pre-commit-hook.sh b/t/t7503-pre-commit-hook.sh index aa294ea428..984889b39d 100755 --- a/t/t7503-pre-commit-hook.sh +++ b/t/t7503-pre-commit-hook.sh @@ -118,7 +118,7 @@ test_expect_success 'with failing hook requiring GIT_PREFIX' ' git checkout -- file ' -test_expect_failure 'check the author in hook' ' +test_expect_success 'check the author in hook' ' write_script "$HOOK" <<-\EOF && test "$GIT_AUTHOR_NAME" = "New Author" && test "$GIT_AUTHOR_EMAIL" = "newauthor@example.com" -- cgit v1.2.3