git-lfs/t/t-install-custom-hooks-path.sh
Taylor Blau f7b1a5c8f8 tools/filetools.go: teach ExpandPath() to do path expansion
In order to expand strings of the form "~/path/to/hooks" into something
like "/home/ttaylorr/path/to/hooks", let's introduce the
tools.ExpandPath() function to do just that.

tools.ExpandPath() inspects the first character of the given string to
see if it begins with a "~" (indicating the presence of a home
directory.

If there is, see also if it refers to a specific "~user", and expand
appropriately.

To ensure that we can run the tests in tools/filetool_test.go in a
platform-independent manner, let's ensure that the results are
_semantically_ equal by first passing them through filepath.ToSlash().

We'll use this in the following commit in order to perform path
expansion on the value of core.hooksPath.
2018-08-30 16:59:33 -04:00

61 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
. "$(dirname "$0")/testlib.sh"
# These tests rely on behavior found in 2.9.0 to perform themselves,
# specifically:
# - core.hooksPath support
ensure_git_version_isnt $VERSION_LOWER "2.9.0"
assert_hooks() {
local hooks_dir="$1"
[ -e "$hooks_dir/pre-push" ]
[ ! -e ".git/pre-push" ]
[ -e "$hooks_dir/post-checkout" ]
[ ! -e ".git/post-checkout" ]
[ -e "$hooks_dir/post-commit" ]
[ ! -e ".git/post-commit" ]
[ -e "$hooks_dir/post-merge" ]
[ ! -e ".git/post-merge" ]
}
begin_test "install with supported core.hooksPath"
(
set -e
repo_name="supported-custom-hooks-path"
git init "$repo_name"
cd "$repo_name"
hooks_dir="custom_hooks_dir"
mkdir -p "$hooks_dir"
git config --local core.hooksPath "$hooks_dir"
git lfs install 2>&1 | tee install.log
grep "Updated git hooks" install.log
assert_hooks "$hooks_dir"
)
end_test
begin_test "install with supported expandable core.hooksPath"
(
set -e
repo_name="supported-custom-hooks-expandable-path"
git init "$repo_name"
cd "$repo_name"
hooks_dir="~/custom_hooks_dir"
mkdir -p "$hooks_dir"
git config --local core.hooksPath "$hooks_dir"
git lfs install 2>&1 | tee install.log
grep "Updated git hooks" install.log
assert_hooks "$HOME/custom_hooks_dir"
)
end_test