forked from git-for-windows/git
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gvfs: add global command pre and post hook procs
This adds hard-coded call to GVFS.hooks.exe before and after each Git command runs. To make sure that this is only called on repositories cloned with GVFS, we test for the tell-tale .gvfs. 2021-10-30: Recent movement of find_hook() to hook.c required moving these changes out of run-command.c to hook.c. Signed-off-by: Ben Peart <Ben.Peart@microsoft.com>
- Loading branch information
Showing
4 changed files
with
199 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/sh | ||
|
||
test_description='pre-command hook' | ||
|
||
. ./test-lib.sh | ||
|
||
test_expect_success 'with no hook' ' | ||
echo "first" > file && | ||
git add file && | ||
git commit -m "first" | ||
' | ||
|
||
test_expect_success 'with succeeding hook' ' | ||
mkdir -p .git/hooks && | ||
write_script .git/hooks/pre-command <<-EOF && | ||
echo "\$*" >\$(git rev-parse --git-dir)/pre-command.out | ||
EOF | ||
echo "second" >> file && | ||
git add file && | ||
test "add file" = "$(cat .git/pre-command.out)" && | ||
echo Hello | git hash-object --stdin && | ||
test "hash-object --stdin" = "$(cat .git/pre-command.out)" | ||
' | ||
|
||
test_expect_success 'with failing hook' ' | ||
write_script .git/hooks/pre-command <<-EOF && | ||
exit 1 | ||
EOF | ||
echo "third" >> file && | ||
test_must_fail git add file && | ||
test_path_is_missing "$(cat .git/pre-command.out)" | ||
' | ||
|
||
test_done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/sh | ||
|
||
test_description='post-command hook' | ||
|
||
. ./test-lib.sh | ||
|
||
test_expect_success 'with no hook' ' | ||
echo "first" > file && | ||
git add file && | ||
git commit -m "first" | ||
' | ||
|
||
test_expect_success 'with succeeding hook' ' | ||
mkdir -p .git/hooks && | ||
write_script .git/hooks/post-command <<-EOF && | ||
echo "\$*" >\$(git rev-parse --git-dir)/post-command.out | ||
EOF | ||
echo "second" >> file && | ||
git add file && | ||
test "add file --exit_code=0" = "$(cat .git/post-command.out)" | ||
' | ||
|
||
test_expect_success 'with failing pre-command hook' ' | ||
write_script .git/hooks/pre-command <<-EOF && | ||
exit 1 | ||
EOF | ||
echo "third" >> file && | ||
test_must_fail git add file && | ||
test_path_is_missing "$(cat .git/post-command.out)" | ||
' | ||
|
||
test_done |