3 . "$(dirname "$0")/testlib.sh"
5 begin_test "install again"
9 smudge="$(git config filter.lfs.smudge)"
10 clean="$(git config filter.lfs.clean)"
11 filter="$(git config filter.lfs.process)"
13 [ "$smudge" = "git-lfs smudge -- %f" ]
14 [ "$clean" = "git-lfs clean -- %f" ]
15 [ "$filter" = "git-lfs filter-process" ]
17 GIT_TRACE=1 git lfs install --skip-repo 2>&1 | tee install.log
19 if grep -q "--replace-all" install.log; then
20 echo >&2 "fatal: unexpected git config --replace-all via 'git lfs install'"
24 [ "$smudge" = "$(git config filter.lfs.smudge)" ]
25 [ "$clean" = "$(git config filter.lfs.clean)" ]
26 [ "$filter" = "$(git config filter.lfs.process)" ]
30 begin_test "install with old (non-upgradeable) settings"
34 git config --global filter.lfs.smudge "git-lfs smudge --something %f"
35 git config --global filter.lfs.clean "git-lfs clean --something %f"
37 git lfs install | tee install.log
38 [ "${PIPESTATUS[0]}" = 0 ]
40 grep -E "(clean|smudge)\" attribute should be" install.log
41 [ `grep -c "(MISSING)" install.log` = "0" ]
43 [ "git-lfs smudge --something %f" = "$(git config --global filter.lfs.smudge)" ]
44 [ "git-lfs clean --something %f" = "$(git config --global filter.lfs.clean)" ]
46 git lfs install --force
47 [ "git-lfs smudge -- %f" = "$(git config --global filter.lfs.smudge)" ]
48 [ "git-lfs clean -- %f" = "$(git config --global filter.lfs.clean)" ]
52 begin_test "install with upgradeable settings"
56 git config --global filter.lfs.smudge "git-lfs smudge %f"
57 git config --global filter.lfs.clean "git-lfs clean %f"
59 # should not need force, should upgrade this old style
61 [ "git-lfs smudge -- %f" = "$(git config --global filter.lfs.smudge)" ]
62 [ "git-lfs clean -- %f" = "$(git config --global filter.lfs.clean)" ]
63 [ "git-lfs filter-process" = "$(git config --global filter.lfs.process)" ]
67 begin_test "install updates repo hooks"
71 mkdir install-repo-hooks
75 pre_push_hook="#!/bin/sh
76 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; }
77 git lfs pre-push \"\$@\""
79 post_checkout_hook="#!/bin/sh
80 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/post-checkout.\\n\"; exit 2; }
81 git lfs post-checkout \"\$@\""
83 post_commit_hook="#!/bin/sh
84 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/post-commit.\\n\"; exit 2; }
85 git lfs post-commit \"\$@\""
87 post_merge_hook="#!/bin/sh
88 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/post-merge.\\n\"; exit 2; }
89 git lfs post-merge \"\$@\""
92 Git LFS initialized." = "$(git lfs install)" ]
93 [ "$pre_push_hook" = "$(cat .git/hooks/pre-push)" ]
94 [ "$post_checkout_hook" = "$(cat .git/hooks/post-checkout)" ]
95 [ "$post_commit_hook" = "$(cat .git/hooks/post-commit)" ]
96 [ "$post_merge_hook" = "$(cat .git/hooks/post-merge)" ]
99 # more-comprehensive hook update tests are in test-update.sh
101 git lfs push --stdin \$*" > .git/hooks/pre-push
102 [ "Updated git hooks.
103 Git LFS initialized." = "$(git lfs install)" ]
104 [ "$pre_push_hook" = "$(cat .git/hooks/pre-push)" ]
106 # don't replace unexpected hook
107 expected="Hook already exists: pre-push
111 To resolve this, either:
112 1: run \`git lfs update --manual\` for instructions on how to merge hooks.
113 2: run \`git lfs update --force\` to overwrite your hook."
115 echo "test" > .git/hooks/pre-push
116 echo "test" > .git/hooks/post-checkout
117 echo "test" > .git/hooks/post-commit
118 echo "test" > .git/hooks/post-merge
119 [ "test" = "$(cat .git/hooks/pre-push)" ]
120 [ "$expected" = "$(git lfs install 2>&1)" ]
121 [ "test" = "$(cat .git/hooks/pre-push)" ]
122 [ "test" = "$(cat .git/hooks/post-checkout)" ]
123 [ "test" = "$(cat .git/hooks/post-commit)" ]
124 [ "test" = "$(cat .git/hooks/post-merge)" ]
126 # Make sure returns non-zero
135 # force replace unexpected hook
136 [ "Updated git hooks.
137 Git LFS initialized." = "$(git lfs install --force)" ]
138 [ "$pre_push_hook" = "$(cat .git/hooks/pre-push)" ]
139 [ "$post_checkout_hook" = "$(cat .git/hooks/post-checkout)" ]
140 [ "$post_commit_hook" = "$(cat .git/hooks/post-commit)" ]
141 [ "$post_merge_hook" = "$(cat .git/hooks/post-merge)" ]
143 has_test_dir || exit 0
145 echo "test with bare repository"
147 git clone --mirror install-repo-hooks bare-install-repo-hooks
148 cd bare-install-repo-hooks
152 [ "$pre_push_hook" = "$(cat hooks/pre-push)" ]
156 begin_test "install outside repository directory"
159 if [ -d "hooks" ]; then
161 echo "hooks dir exists"
165 git lfs install 2>&1 > check.log
167 if [ -d "hooks" ]; then
169 echo "hooks dir exists"
175 # doesn't print this because being in a git repo is not necessary for install
176 [ "$(grep -c "Not in a git repository" check.log)" = "0" ]
180 begin_test "install --skip-smudge"
184 mkdir install-skip-smudge-test
185 cd install-skip-smudge-test
188 [ "git-lfs clean -- %f" = "$(git config --global filter.lfs.clean)" ]
189 [ "git-lfs smudge -- %f" = "$(git config --global filter.lfs.smudge)" ]
190 [ "git-lfs filter-process" = "$(git config --global filter.lfs.process)" ]
192 git lfs install --skip-smudge
193 [ "git-lfs clean -- %f" = "$(git config --global filter.lfs.clean)" ]
194 [ "git-lfs smudge --skip -- %f" = "$(git config --global filter.lfs.smudge)" ]
195 [ "git-lfs filter-process --skip" = "$(git config --global filter.lfs.process)" ]
198 [ "git-lfs clean -- %f" = "$(git config --global filter.lfs.clean)" ]
199 [ "git-lfs smudge -- %f" = "$(git config --global filter.lfs.smudge)" ]
200 [ "git-lfs filter-process" = "$(git config --global filter.lfs.process)" ]
206 begin_test "install --local"
210 # old values that should be ignored by `install --local`
211 git config --global filter.lfs.smudge "git lfs smudge %f"
212 git config --global filter.lfs.clean "git lfs clean %f"
214 mkdir install-local-repo
215 cd install-local-repo
217 git lfs install --local
219 [ "git-lfs clean -- %f" = "$(git config filter.lfs.clean)" ]
220 [ "git-lfs clean -- %f" = "$(git config --local filter.lfs.clean)" ]
221 [ "git lfs clean %f" = "$(git config --global filter.lfs.clean)" ]
222 [ "git-lfs filter-process" = "$(git config filter.lfs.process)" ]
223 [ "git-lfs filter-process" = "$(git config --local filter.lfs.process)" ]
227 begin_test "install --local outside repository"
229 # If run inside the git-lfs source dir this will update its .git/config & cause issues
230 if [ "$GIT_LFS_TEST_DIR" == "" ]; then
231 echo "Skipping install --local because GIT_LFS_TEST_DIR is not set"
237 has_test_dir || exit 0
239 git lfs install --local 2> err.log
242 [ "Not in a git repository." = "$(cat err.log)" ]
247 begin_test "install in directory without access to .git/lfs"
256 git config --global filter.lfs.clean whatevs
257 [ "whatevs" = "$(git config filter.lfs.clean)" ]
259 git lfs install --force
261 [ "git-lfs clean -- %f" = "$(git config filter.lfs.clean)" ]
266 begin_test "install in repo without changing hooks"
269 git init non-lfs-repo
272 git lfs install --skip-repo
274 # should not install hooks
275 [ ! -f .git/hooks/pre-push ]
276 [ ! -f .git/hooks/post-checkout ]
277 [ ! -f .git/hooks/post-merge ]
278 [ ! -f .git/hooks/post-commit ]
280 # filters should still be installed
281 [ "git-lfs clean -- %f" = "$(git config filter.lfs.clean)" ]
282 [ "git-lfs smudge -- %f" = "$(git config filter.lfs.smudge)" ]
283 [ "git-lfs filter-process" = "$(git config filter.lfs.process)" ]
288 begin_test "can install when multiple global values registered"
292 git config --global filter.lfs.smudge "git-lfs smudge --something %f"
293 git config --global --add filter.lfs.smudge "git-lfs smudge --something-else %f"
295 git lfs install --force