2015-07-30 02:37:31 +00:00
#!/usr/bin/env bash
2015-06-28 12:48:59 +00:00
2018-07-10 18:48:02 +00:00
. " $( dirname " $0 " ) /testlib.sh "
2015-06-28 12:48:59 +00:00
2015-11-16 20:31:26 +00:00
begin_test "install again"
2015-06-28 12:48:59 +00:00
(
2018-05-04 16:07:25 +00:00
set -eo pipefail
2015-06-28 12:48:59 +00:00
2015-10-26 23:12:15 +00:00
smudge = " $( git config filter.lfs.smudge) "
clean = " $( git config filter.lfs.clean) "
2016-11-08 14:44:51 +00:00
filter = " $( git config filter.lfs.process) "
2015-10-26 23:12:15 +00:00
2018-05-04 16:07:25 +00:00
[ " $smudge " = "git-lfs smudge -- %f" ]
[ " $clean " = "git-lfs clean -- %f" ]
[ " $filter " = "git-lfs filter-process" ]
2015-06-28 12:48:59 +00:00
2018-05-04 16:07:25 +00:00
GIT_TRACE = 1 git lfs install --skip-repo 2>& 1 | tee install.log
if grep -q "--replace-all" install.log; then
echo >& 2 "fatal: unexpected git config --replace-all via 'git lfs install'"
exit 1
fi
2015-06-28 12:48:59 +00:00
2015-10-26 23:12:15 +00:00
[ " $smudge " = " $( git config filter.lfs.smudge) " ]
[ " $clean " = " $( git config filter.lfs.clean) " ]
2016-11-08 14:44:51 +00:00
[ " $filter " = " $( git config filter.lfs.process) " ]
2015-06-28 12:48:59 +00:00
)
end_test
2016-09-01 11:29:49 +00:00
begin_test "install with old (non-upgradeable) settings"
2015-06-28 12:48:59 +00:00
(
set -e
2016-09-01 11:29:49 +00:00
git config --global filter.lfs.smudge "git-lfs smudge --something %f"
git config --global filter.lfs.clean "git-lfs clean --something %f"
2015-06-28 12:48:59 +00:00
2017-10-17 16:41:51 +00:00
git lfs install | tee install.log
2019-04-23 20:56:40 +00:00
[ " ${ PIPESTATUS [0] } " = 2 ]
2015-06-28 12:48:59 +00:00
2017-10-17 16:41:51 +00:00
grep -E "(clean|smudge)\" attribute should be" install.log
2015-11-16 20:31:26 +00:00
[ ` grep -c "(MISSING)" install.log` = "0" ]
2015-06-28 12:48:59 +00:00
2016-09-01 11:29:49 +00:00
[ "git-lfs smudge --something %f" = " $( git config --global filter.lfs.smudge) " ]
[ "git-lfs clean --something %f" = " $( git config --global filter.lfs.clean) " ]
2015-07-06 23:12:31 +00:00
2015-11-16 20:31:26 +00:00
git lfs install --force
2019-04-23 20:56:40 +00:00
2016-03-17 21:25:33 +00:00
[ "git-lfs smudge -- %f" = " $( git config --global filter.lfs.smudge) " ]
[ "git-lfs clean -- %f" = " $( git config --global filter.lfs.clean) " ]
2015-06-28 12:48:59 +00:00
)
end_test
2015-08-13 23:13:00 +00:00
2016-09-01 11:29:49 +00:00
begin_test "install with upgradeable settings"
(
set -e
git config --global filter.lfs.smudge "git-lfs smudge %f"
git config --global filter.lfs.clean "git-lfs clean %f"
# should not need force, should upgrade this old style
git lfs install
[ "git-lfs smudge -- %f" = " $( git config --global filter.lfs.smudge) " ]
[ "git-lfs clean -- %f" = " $( git config --global filter.lfs.clean) " ]
2016-11-08 20:05:12 +00:00
[ "git-lfs filter-process" = " $( git config --global filter.lfs.process) " ]
2016-09-01 11:29:49 +00:00
)
end_test
2015-11-16 20:31:26 +00:00
begin_test "install updates repo hooks"
2015-08-13 23:13:00 +00:00
(
set -e
2015-11-16 20:31:26 +00:00
mkdir install-repo-hooks
cd install-repo-hooks
2015-08-13 23:13:00 +00:00
git init
pre_push_hook = " #!/bin/sh
hooks: mention core.hookspath instead of just .git/hooks
In some cases, users may use `core.hooksPath` to locate their hooks in a
different location. However, right now, our hook and installation
instructions mention only `.git/hooks`.
We can update the instructions without a problem, but we don't want to
hard-code the hook path into the hooks themselves because of things like
symlinks and moved repository, plus the fact that we can't update a hook
automatically unless it's identical minus some whitespace changes. To
avoid spuriously failing to update a hook, let's print the right
location with the instructions, and just mention `core.hookspath` and
`.git/hooks` in the message, leaving it to the user to discover.
Note that technically, core.hookspath was not implemented until Git
2.9.0. However, while we still support older versions of Git, no
presently supported version of Ubuntu or Debian offers a version older
than 2.11, so the risk of practical confusion by mentioning this is low.
Nevertheless, make our tests pass by checking for an old Git explicitly.
2023-01-04 19:48:38 +00:00
command -v git-lfs >/dev/null 2>& 1 || { echo >& 2 \" \\ nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory ( set by 'core.hookspath' ; usually '.git/hooks' ) .\\ n\" ; exit 2; }
2015-08-13 23:13:00 +00:00
git lfs pre-push \" \$ @\" "
2017-01-02 13:07:53 +00:00
post_checkout_hook = " #!/bin/sh
hooks: mention core.hookspath instead of just .git/hooks
In some cases, users may use `core.hooksPath` to locate their hooks in a
different location. However, right now, our hook and installation
instructions mention only `.git/hooks`.
We can update the instructions without a problem, but we don't want to
hard-code the hook path into the hooks themselves because of things like
symlinks and moved repository, plus the fact that we can't update a hook
automatically unless it's identical minus some whitespace changes. To
avoid spuriously failing to update a hook, let's print the right
location with the instructions, and just mention `core.hookspath` and
`.git/hooks` in the message, leaving it to the user to discover.
Note that technically, core.hookspath was not implemented until Git
2.9.0. However, while we still support older versions of Git, no
presently supported version of Ubuntu or Debian offers a version older
than 2.11, so the risk of practical confusion by mentioning this is low.
Nevertheless, make our tests pass by checking for an old Git explicitly.
2023-01-04 19:48:38 +00:00
command -v git-lfs >/dev/null 2>& 1 || { echo >& 2 \" \\ nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-checkout' file in the hooks directory ( set by 'core.hookspath' ; usually '.git/hooks' ) .\\ n\" ; exit 2; }
2017-01-02 13:07:53 +00:00
git lfs post-checkout \" \$ @\" "
2017-01-02 14:36:28 +00:00
post_commit_hook = " #!/bin/sh
hooks: mention core.hookspath instead of just .git/hooks
In some cases, users may use `core.hooksPath` to locate their hooks in a
different location. However, right now, our hook and installation
instructions mention only `.git/hooks`.
We can update the instructions without a problem, but we don't want to
hard-code the hook path into the hooks themselves because of things like
symlinks and moved repository, plus the fact that we can't update a hook
automatically unless it's identical minus some whitespace changes. To
avoid spuriously failing to update a hook, let's print the right
location with the instructions, and just mention `core.hookspath` and
`.git/hooks` in the message, leaving it to the user to discover.
Note that technically, core.hookspath was not implemented until Git
2.9.0. However, while we still support older versions of Git, no
presently supported version of Ubuntu or Debian offers a version older
than 2.11, so the risk of practical confusion by mentioning this is low.
Nevertheless, make our tests pass by checking for an old Git explicitly.
2023-01-04 19:48:38 +00:00
command -v git-lfs >/dev/null 2>& 1 || { echo >& 2 \" \\ nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-commit' file in the hooks directory ( set by 'core.hookspath' ; usually '.git/hooks' ) .\\ n\" ; exit 2; }
2017-01-02 14:36:28 +00:00
git lfs post-commit \" \$ @\" "
2017-01-02 16:56:47 +00:00
post_merge_hook = " #!/bin/sh
hooks: mention core.hookspath instead of just .git/hooks
In some cases, users may use `core.hooksPath` to locate their hooks in a
different location. However, right now, our hook and installation
instructions mention only `.git/hooks`.
We can update the instructions without a problem, but we don't want to
hard-code the hook path into the hooks themselves because of things like
symlinks and moved repository, plus the fact that we can't update a hook
automatically unless it's identical minus some whitespace changes. To
avoid spuriously failing to update a hook, let's print the right
location with the instructions, and just mention `core.hookspath` and
`.git/hooks` in the message, leaving it to the user to discover.
Note that technically, core.hookspath was not implemented until Git
2.9.0. However, while we still support older versions of Git, no
presently supported version of Ubuntu or Debian offers a version older
than 2.11, so the risk of practical confusion by mentioning this is low.
Nevertheless, make our tests pass by checking for an old Git explicitly.
2023-01-04 19:48:38 +00:00
command -v git-lfs >/dev/null 2>& 1 || { echo >& 2 \" \\ nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-merge' file in the hooks directory ( set by 'core.hookspath' ; usually '.git/hooks' ) .\\ n\" ; exit 2; }
2017-01-02 16:56:47 +00:00
git lfs post-merge \" \$ @\" "
2022-01-29 00:44:16 +00:00
[ " Updated Git hooks.
2015-11-16 20:31:26 +00:00
Git LFS initialized." = " $( git lfs install) " ]
2015-08-13 23:13:00 +00:00
[ " $pre_push_hook " = " $( cat .git/hooks/pre-push) " ]
2017-01-02 13:07:53 +00:00
[ " $post_checkout_hook " = " $( cat .git/hooks/post-checkout) " ]
2017-01-02 14:36:28 +00:00
[ " $post_commit_hook " = " $( cat .git/hooks/post-commit) " ]
2017-01-02 16:56:47 +00:00
[ " $post_merge_hook " = " $( cat .git/hooks/post-merge) " ]
2015-08-13 23:13:00 +00:00
# replace old hook
# more-comprehensive hook update tests are in test-update.sh
echo " #!/bin/sh
git lfs push --stdin \$ *" > .git/hooks/pre-push
2022-01-29 00:44:16 +00:00
[ " Updated Git hooks.
2015-11-16 20:31:26 +00:00
Git LFS initialized." = " $( git lfs install) " ]
2015-08-13 23:13:00 +00:00
[ " $pre_push_hook " = " $( cat .git/hooks/pre-push) " ]
# don't replace unexpected hook
expected = " Hook already exists: pre-push
2017-07-06 17:43:48 +00:00
test
2015-08-13 23:13:00 +00:00
2016-04-26 11:04:55 +00:00
To resolve this, either:
1: run \` git lfs update --manual\` for instructions on how to merge hooks.
2: run \` git lfs update --force\` to overwrite your hook."
2015-08-13 23:13:00 +00:00
echo "test" > .git/hooks/pre-push
2017-01-02 13:07:53 +00:00
echo "test" > .git/hooks/post-checkout
2017-01-02 14:36:28 +00:00
echo "test" > .git/hooks/post-commit
2017-01-02 16:56:47 +00:00
echo "test" > .git/hooks/post-merge
2015-08-13 23:13:00 +00:00
[ "test" = " $( cat .git/hooks/pre-push) " ]
2015-11-16 20:31:26 +00:00
[ " $expected " = " $( git lfs install 2>& 1) " ]
2015-08-13 23:13:00 +00:00
[ "test" = " $( cat .git/hooks/pre-push) " ]
2017-01-02 13:07:53 +00:00
[ "test" = " $( cat .git/hooks/post-checkout) " ]
2017-01-02 14:36:28 +00:00
[ "test" = " $( cat .git/hooks/post-commit) " ]
2017-01-02 16:56:47 +00:00
[ "test" = " $( cat .git/hooks/post-merge) " ]
2015-08-13 23:13:00 +00:00
2016-04-25 09:56:38 +00:00
# Make sure returns non-zero
set +e
git lfs install
if [ $? -eq 0 ]
then
exit 1
fi
set -e
2015-08-13 23:13:00 +00:00
# force replace unexpected hook
2022-01-29 00:44:16 +00:00
[ " Updated Git hooks.
2015-11-16 20:31:26 +00:00
Git LFS initialized." = " $( git lfs install --force) " ]
2015-08-13 23:13:00 +00:00
[ " $pre_push_hook " = " $( cat .git/hooks/pre-push) " ]
2017-01-02 13:07:53 +00:00
[ " $post_checkout_hook " = " $( cat .git/hooks/post-checkout) " ]
2017-01-02 14:36:28 +00:00
[ " $post_commit_hook " = " $( cat .git/hooks/post-commit) " ]
2017-01-02 16:56:47 +00:00
[ " $post_merge_hook " = " $( cat .git/hooks/post-merge) " ]
2015-09-17 22:35:04 +00:00
2015-10-26 23:12:15 +00:00
has_test_dir || exit 0
2015-09-30 23:38:13 +00:00
2015-09-17 22:35:04 +00:00
echo "test with bare repository"
cd ..
2015-11-16 20:31:26 +00:00
git clone --mirror install-repo-hooks bare-install-repo-hooks
cd bare-install-repo-hooks
2015-09-17 22:37:25 +00:00
git lfs env
2015-11-16 20:31:26 +00:00
git lfs install
2015-09-17 22:37:25 +00:00
ls -al hooks
2015-09-17 22:35:04 +00:00
[ " $pre_push_hook " = " $( cat hooks/pre-push) " ]
2015-08-13 23:13:00 +00:00
)
end_test
2015-09-23 17:58:16 +00:00
2015-11-16 20:31:26 +00:00
begin_test "install outside repository directory"
2015-10-19 20:47:18 +00:00
(
set -e
if [ -d "hooks" ] ; then
ls -al
echo "hooks dir exists"
exit 1
fi
2020-01-03 15:55:26 +00:00
git lfs install > check.log 2>& 1
2015-10-19 20:47:18 +00:00
if [ -d "hooks" ] ; then
ls -al
echo "hooks dir exists"
exit 1
fi
cat check.log
2015-11-16 20:31:26 +00:00
# doesn't print this because being in a git repo is not necessary for install
2022-01-29 00:44:16 +00:00
[ " $( grep -c "Not in a Git repository" check.log) " = "0" ]
2020-01-03 15:55:26 +00:00
[ " $( grep -c "Error" check.log) " = "0" ]
2015-10-19 20:47:18 +00:00
)
end_test
2015-11-16 20:31:26 +00:00
begin_test "install --skip-smudge"
2015-09-23 18:20:30 +00:00
(
set -e
2016-11-30 20:43:46 +00:00
mkdir install-skip-smudge-test
cd install-skip-smudge-test
2015-11-16 20:31:26 +00:00
git lfs install
2016-03-17 21:25:33 +00:00
[ "git-lfs clean -- %f" = " $( git config --global filter.lfs.clean) " ]
[ "git-lfs smudge -- %f" = " $( git config --global filter.lfs.smudge) " ]
2016-11-08 20:05:12 +00:00
[ "git-lfs filter-process" = " $( git config --global filter.lfs.process) " ]
2015-09-23 18:20:30 +00:00
2015-11-16 20:31:26 +00:00
git lfs install --skip-smudge
2016-03-17 21:25:33 +00:00
[ "git-lfs clean -- %f" = " $( git config --global filter.lfs.clean) " ]
[ "git-lfs smudge --skip -- %f" = " $( git config --global filter.lfs.smudge) " ]
2016-11-08 20:05:12 +00:00
[ "git-lfs filter-process --skip" = " $( git config --global filter.lfs.process) " ]
2015-09-23 18:20:30 +00:00
2017-10-17 16:07:26 +00:00
git lfs install
2016-03-17 21:25:33 +00:00
[ "git-lfs clean -- %f" = " $( git config --global filter.lfs.clean) " ]
[ "git-lfs smudge -- %f" = " $( git config --global filter.lfs.smudge) " ]
2016-11-08 20:05:12 +00:00
[ "git-lfs filter-process" = " $( git config --global filter.lfs.process) " ]
2016-11-30 20:43:46 +00:00
[ ! -e "lfs" ]
2015-09-23 18:20:30 +00:00
)
end_test
2015-11-16 20:31:26 +00:00
begin_test "install --local"
2015-09-23 17:58:16 +00:00
(
set -e
2015-11-16 20:31:26 +00:00
# old values that should be ignored by `install --local`
2020-06-16 19:25:51 +00:00
git config --global filter.lfs.smudge "global smudge"
git config --global filter.lfs.clean "global clean"
git config --global filter.lfs.process "global filter"
2015-09-23 17:58:16 +00:00
2015-11-16 20:31:26 +00:00
mkdir install-local-repo
cd install-local-repo
2015-09-23 17:58:16 +00:00
git init
2015-11-16 20:31:26 +00:00
git lfs install --local
2015-09-23 17:58:16 +00:00
2020-06-16 19:25:51 +00:00
# local configs are correct
[ "git-lfs smudge -- %f" = " $( git config filter.lfs.smudge) " ]
[ "git-lfs smudge -- %f" = " $( git config --local filter.lfs.smudge) " ]
2016-03-17 21:25:33 +00:00
[ "git-lfs clean -- %f" = " $( git config filter.lfs.clean) " ]
[ "git-lfs clean -- %f" = " $( git config --local filter.lfs.clean) " ]
2016-11-08 20:05:12 +00:00
[ "git-lfs filter-process" = " $( git config filter.lfs.process) " ]
[ "git-lfs filter-process" = " $( git config --local filter.lfs.process) " ]
2020-06-16 19:25:51 +00:00
# global configs
[ "global smudge" = " $( git config --global filter.lfs.smudge) " ]
[ "global clean" = " $( git config --global filter.lfs.clean) " ]
[ "global filter" = " $( git config --global filter.lfs.process) " ]
2015-09-23 17:58:16 +00:00
)
end_test
2023-05-02 14:11:27 +00:00
begin_test "install --file"
(
set -e
# old values that should be ignored by `install --local`
git config --global filter.lfs.smudge "global smudge"
git config --global filter.lfs.clean "global clean"
git config --global filter.lfs.process "global filter"
mkdir install-file-repo
cd install-file-repo
git init
git lfs install --file= test-file
# local configs are correct
[ "git-lfs smudge -- %f" = " $( git config --file test-file filter.lfs.smudge) " ]
[ "git-lfs clean -- %f" = " $( git config --file test-file filter.lfs.clean) " ]
[ "git-lfs filter-process" = " $( git config --file test-file filter.lfs.process) " ]
# global configs
[ "global smudge" = " $( git config --global filter.lfs.smudge) " ]
[ "global clean" = " $( git config --global filter.lfs.clean) " ]
[ "global filter" = " $( git config --global filter.lfs.process) " ]
)
end_test
2019-04-23 20:56:40 +00:00
begin_test "install --local with failed permissions"
(
set -e
# Windows lacks POSIX permissions.
[ " $IS_WINDOWS " -eq 1 ] && exit 0
2019-06-28 16:52:49 +00:00
# Root is exempt from permissions.
[ " $( id -u) " -eq 0 ] && exit 0
2019-04-23 20:56:40 +00:00
mkdir install-local-repo-perms
cd install-local-repo-perms
git init
# Make it impossible to write a new .git/config file so we can't write config
# options.
chmod 500 .git
res = 0
2020-06-16 18:43:42 +00:00
git lfs install --local >out.log || res = $?
2019-04-23 20:56:40 +00:00
# Cleanup fails without this.
chmod 700 .git
2020-06-16 18:43:42 +00:00
cat out.log
grep -E "error running.*git.*config" out.log
2019-04-23 20:56:40 +00:00
[ " $res " -eq 2 ]
)
end_test
2015-11-16 20:31:26 +00:00
begin_test "install --local outside repository"
2015-09-23 17:58:16 +00:00
(
2020-06-16 18:43:42 +00:00
set -e
2015-10-22 09:56:57 +00:00
# If run inside the git-lfs source dir this will update its .git/config & cause issues
if [ " $GIT_LFS_TEST_DIR " = = "" ] ; then
2015-11-16 20:31:26 +00:00
echo "Skipping install --local because GIT_LFS_TEST_DIR is not set"
2015-10-22 09:56:57 +00:00
exit 0
fi
2015-10-26 23:12:15 +00:00
has_test_dir || exit 0
2015-09-30 23:43:43 +00:00
2020-06-16 18:43:42 +00:00
set +e
git lfs install --local >out.log
2015-09-23 17:58:16 +00:00
res = $?
2020-06-16 18:43:42 +00:00
set -e
2015-09-23 17:58:16 +00:00
2022-01-29 00:44:16 +00:00
[ "Not in a Git repository." = " $( cat out.log) " ]
2015-09-23 17:58:16 +00:00
[ "0" != " $res " ]
)
end_test
2016-11-30 20:43:46 +00:00
2020-06-16 19:25:51 +00:00
begin_test "install --local with conflicting scope"
(
set -e
reponame = " $( basename " $0 " ".sh" ) -scope-conflict "
mkdir " $reponame "
cd " $reponame "
git init
set +e
git lfs install --local --system 2>err.log
res = $?
set -e
2023-05-02 14:11:27 +00:00
[ "Only one of the --local, --system, --worktree, and --file options can be specified." = " $( cat err.log) " ]
2020-06-16 19:25:51 +00:00
[ "0" != " $res " ]
)
end_test
2016-11-30 20:43:46 +00:00
begin_test "install in directory without access to .git/lfs"
(
set -e
mkdir not-a-repo
cd not-a-repo
mkdir .git
touch .git/lfs
touch lfs
git config --global filter.lfs.clean whatevs
[ "whatevs" = " $( git config filter.lfs.clean) " ]
git lfs install --force
[ "git-lfs clean -- %f" = " $( git config filter.lfs.clean) " ]
)
end_test
2017-01-16 12:39:55 +00:00
begin_test "install in repo without changing hooks"
(
set -e
git init non-lfs-repo
cd non-lfs-repo
git lfs install --skip-repo
# should not install hooks
[ ! -f .git/hooks/pre-push ]
[ ! -f .git/hooks/post-checkout ]
[ ! -f .git/hooks/post-merge ]
[ ! -f .git/hooks/post-commit ]
# filters should still be installed
[ "git-lfs clean -- %f" = " $( git config filter.lfs.clean) " ]
[ "git-lfs smudge -- %f" = " $( git config filter.lfs.smudge) " ]
[ "git-lfs filter-process" = " $( git config filter.lfs.process) " ]
)
end_test
2017-10-10 04:33:23 +00:00
begin_test "can install when multiple global values registered"
(
set -e
git config --global filter.lfs.smudge "git-lfs smudge --something %f"
git config --global --add filter.lfs.smudge "git-lfs smudge --something-else %f"
git lfs install --force
)
end_test