2015-07-30 02:37:31 +00:00
#!/usr/bin/env bash
2015-06-28 12:48:59 +00:00
. "test/testlib.sh"
2015-11-16 20:31:26 +00:00
begin_test "install again"
2015-06-28 12:48:59 +00:00
(
set -e
2015-10-26 23:12:15 +00:00
smudge = " $( git config filter.lfs.smudge) "
clean = " $( git config filter.lfs.clean) "
printf " $smudge " | grep "git-lfs smudge"
printf " $clean " | grep "git-lfs clean"
2015-06-28 12:48:59 +00:00
2015-11-16 20:31:26 +00:00
git lfs install
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) " ]
2015-06-28 12:48:59 +00:00
)
end_test
2015-11-16 20:31:26 +00:00
begin_test "install with old settings"
2015-06-28 12:48:59 +00:00
(
set -e
git config --global filter.lfs.smudge "git lfs smudge %f"
git config --global filter.lfs.clean "git lfs clean %f"
2015-07-06 23:12:31 +00:00
set +e
2015-11-16 20:31:26 +00:00
git lfs install 2> install.log
2015-07-06 23:12:31 +00:00
res = $?
set -e
[ " $res " = 2 ]
2015-06-28 12:48:59 +00:00
2015-11-16 20:31:26 +00:00
cat install.log
grep -E "(clean|smudge) attribute should be" install.log
[ ` grep -c "(MISSING)" install.log` = "0" ]
2015-06-28 12:48:59 +00:00
2015-10-26 23:12:15 +00:00
[ "git lfs smudge %f" = " $( git config --global filter.lfs.smudge) " ]
[ "git lfs clean %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
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
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
2015-08-14 15:59:16 +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 .git/hooks/pre-push.\\ n\" ; exit 2; }
2015-08-13 23:13:00 +00:00
git lfs pre-push \" \$ @\" "
[ " Updated pre-push hook.
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) " ]
# replace old hook
# more-comprehensive hook update tests are in test-update.sh
echo " #!/bin/sh
git lfs push --stdin \$ *" > .git/hooks/pre-push
[ " Updated pre-push hook.
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
test
Run \` git lfs update --force\` to overwrite this hook.
Git LFS initialized."
echo "test" > .git/hooks/pre-push
[ "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) " ]
# force replace unexpected hook
[ " Updated pre-push hook.
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) " ]
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
2015-11-16 20:31:26 +00:00
git lfs install 2>& 1 > check.log
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
2015-10-19 20:47:18 +00:00
[ " $( grep -c "Not in a git repository" check.log) " = "0" ]
)
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
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) " ]
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) " ]
2015-09-23 18:20:30 +00:00
2015-11-16 20:31:26 +00:00
git lfs install --force
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) " ]
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`
2015-09-23 17:58:16 +00:00
git config --global filter.lfs.smudge "git lfs smudge %f"
git config --global filter.lfs.clean "git lfs clean %f"
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
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) " ]
2015-09-23 17:58:16 +00:00
[ "git lfs clean %f" = " $( git config --global filter.lfs.clean) " ]
)
end_test
2015-11-16 20:31:26 +00:00
begin_test "install --local outside repository"
2015-09-23 17:58:16 +00:00
(
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-09-23 17:58:16 +00:00
set +e
2015-09-30 23:43:43 +00:00
2015-10-26 23:12:15 +00:00
has_test_dir || exit 0
2015-09-30 23:43:43 +00:00
2015-11-16 20:31:26 +00:00
git lfs install --local 2> err.log
2015-09-23 17:58:16 +00:00
res = $?
[ "Not in a git repository." = " $( cat err.log) " ]
[ "0" != " $res " ]
)
end_test