| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | # These tests rely on behavior found in 2.9.0 to perform themselves, |
| 6 | # specifically: |
| 7 | # - core.hooksPath support |
| 8 | ensure_git_version_isnt $VERSION_LOWER "2.9.0" |
| 9 | |
| 10 | assert_hooks() { |
| 11 | local hooks_dir="$1" |
| 12 | [ -e "$hooks_dir/pre-push" ] |
| 13 | [ ! -e ".git/pre-push" ] |
| 14 | [ -e "$hooks_dir/post-checkout" ] |
| 15 | [ ! -e ".git/post-checkout" ] |
| 16 | [ -e "$hooks_dir/post-commit" ] |
| 17 | [ ! -e ".git/post-commit" ] |
| 18 | [ -e "$hooks_dir/post-merge" ] |
| 19 | [ ! -e ".git/post-merge" ] |
| 20 | } |
| 21 | |
| 22 | refute_hooks() { |
| 23 | local hooks_dir="$1" |
| 24 | [ ! -e "$hooks_dir/pre-push" ] |
| 25 | [ ! -e "$hooks_dir/post-checkout" ] |
| 26 | [ ! -e "$hooks_dir/post-commit" ] |
| 27 | [ ! -e "$hooks_dir/post-merge" ] |
| 28 | } |
| 29 | |
| 30 | begin_test "install with supported core.hooksPath" |
| 31 | ( |
| 32 | set -e |
| 33 | |
| 34 | repo_name="supported-custom-hooks-path" |
| 35 | git init "$repo_name" |
| 36 | cd "$repo_name" |
| 37 | |
| 38 | hooks_dir="custom_hooks_dir" |
| 39 | mkdir -p "$hooks_dir" |
| 40 | |
| 41 | git config --local core.hooksPath "$hooks_dir" |
| 42 | |
| 43 | git lfs install 2>&1 | tee install.log |
| 44 | grep "Updated Git hooks" install.log |
| 45 | |
| 46 | assert_hooks "$hooks_dir" |
| 47 | ) |
| 48 | end_test |
| 49 | |
| 50 | begin_test "install with supported core.hooksPath in subdirectory" |
| 51 | ( |
| 52 | set -e |
| 53 | |
| 54 | repo_name="supported-custom-hooks-path-subdir" |
| 55 | git init "$repo_name" |
| 56 | cd "$repo_name" |
| 57 | |
| 58 | hooks_dir="custom_hooks_dir" |
| 59 | |
| 60 | mkdir subdir |
| 61 | |
| 62 | git config --local core.hooksPath "$hooks_dir" |
| 63 | |
| 64 | (cd subdir && git lfs install 2>&1 | tee install.log) |
| 65 | grep "Updated Git hooks" subdir/install.log |
| 66 | |
| 67 | assert_hooks "$hooks_dir" |
| 68 | refute_hooks "subdir/$hooks_dir" |
| 69 | ) |
| 70 | end_test |
| 71 | |
| 72 | begin_test "install with supported expandable core.hooksPath" |
| 73 | ( |
| 74 | set -e |
| 75 | |
| 76 | repo_name="supported-custom-hooks-expandable-path" |
| 77 | git init "$repo_name" |
| 78 | cd "$repo_name" |
| 79 | |
| 80 | hooks_dir="~/custom_hooks_dir" |
| 81 | mkdir -p "$hooks_dir" |
| 82 | |
| 83 | git config --local core.hooksPath "$hooks_dir" |
| 84 | |
| 85 | git lfs install 2>&1 | tee install.log |
| 86 | grep "Updated Git hooks" install.log |
| 87 | |
| 88 | assert_hooks "$HOME/custom_hooks_dir" |
| 89 | ) |
| 90 | end_test |