Skip to content

Commit 4f03c17

Browse files
committed
t/t-{checkout,pull}.sh: add read-only error tests
In a previous commit in this PR we adjusted the "git lfs checkout" and "git lfs pull" commands so that when a Git LFS object's contents can not be written to a file in the working tree, the commands output a detailed set of error messages rather than just the message "could not check out <filepath>". We now add tests to our t-checkout.sh and t-pull.sh test scripts which validate this change. Specifically, the new "checkout: read-only directory" and "pull: read-only directory" tests remove write permissions on a directory in the working tree after removing a file which is tracked as a Git LFS object from the directory. The tests then check that the "git lfs checkout" and "git lfs pull" commands output a full set of error messages when they are unable to re-create the file. Note that for historical reasons we expect that under these conditions the commands will return a zero exit code, indicating success, rather than a non-zero exit code, which would indicate failure. We may adjust this behaviour in the future, however, so that the commands also return a non-zero exit code in these cases.
1 parent 8415f3d commit 4f03c17

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

t/t-checkout.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,45 @@ begin_test "checkout: outside git repository"
159159
)
160160
end_test
161161

162+
begin_test "checkout: read-only directory"
163+
(
164+
set -e
165+
166+
reponame="checkout-read-only"
167+
git init "$reponame"
168+
cd "$reponame"
169+
170+
git lfs track "*.bin"
171+
172+
contents="a"
173+
contents_oid=$(calc_oid "$contents")
174+
mkdir dir
175+
printf "%s" "$contents" > dir/a.bin
176+
177+
git add .gitattributes dir/a.bin
178+
git commit -m "add dir/a.bin"
179+
180+
rm dir/a.bin
181+
182+
chmod a-w dir
183+
git lfs checkout 2>&1 | tee checkout.log
184+
# Note that although the checkout command should log an error, at present
185+
# we still expect a zero exit code.
186+
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
187+
echo >&2 "fatal: expected 'git lfs checkout' to succeed ..."
188+
exit 1
189+
fi
190+
191+
assert_local_object "$contents_oid" 1
192+
193+
[ ! -e dir/a.bin ]
194+
195+
grep 'could not check out "dir/a.bin"' checkout.log
196+
grep 'could not create working directory file' checkout.log
197+
grep 'permission denied' checkout.log
198+
)
199+
end_test
200+
162201
begin_test "checkout: write-only file"
163202
(
164203
set -e

t/t-pull.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,50 @@ begin_test "pull: outside git repository"
366366
)
367367
end_test
368368

369+
begin_test "pull: read-only directory"
370+
(
371+
set -e
372+
373+
reponame="pull-read-only"
374+
setup_remote_repo "$reponame"
375+
clone_repo "$reponame" "$reponame"
376+
377+
git lfs track "*.bin"
378+
379+
contents="a"
380+
contents_oid=$(calc_oid "$contents")
381+
mkdir dir
382+
printf "%s" "$contents" > dir/a.bin
383+
384+
git add .gitattributes dir/a.bin
385+
git commit -m "add dir/a.bin"
386+
387+
git push origin main
388+
389+
assert_server_object "$reponame" "$contents_oid"
390+
391+
rm dir/a.bin
392+
delete_local_object "$contents_oid"
393+
394+
chmod a-w dir
395+
git lfs pull 2>&1 | tee pull.log
396+
# Note that although the pull command should log an error, at present
397+
# we still expect a zero exit code.
398+
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
399+
echo >&2 "fatal: expected 'git lfs pull' to succeed ..."
400+
exit 1
401+
fi
402+
403+
assert_local_object "$contents_oid" 1
404+
405+
[ ! -e dir/a.bin ]
406+
407+
grep 'could not check out "dir/a.bin"' pull.log
408+
grep 'could not create working directory file' pull.log
409+
grep 'permission denied' pull.log
410+
)
411+
end_test
412+
369413
begin_test "pull with empty file doesn't modify mtime"
370414
(
371415
set -e

0 commit comments

Comments
 (0)