commands/smudge: treat empty pointers as empty files

Closes git-lfs/git-lfs#1922.
This commit is contained in:
Taylor Blau 2017-02-16 17:38:15 -07:00
parent 09f6330aaa
commit ac42f82430
2 changed files with 42 additions and 5 deletions

@ -23,7 +23,8 @@ var (
//
// If the encoded LFS pointer is not parse-able as a pointer, the contents of
// that file will instead be spooled to a temporary location on disk and then
// copied out back to Git.
// copied out back to Git. If the pointer file is empty, an empty file will be
// written with no error.
//
// If the smudged object did not "pass" the include and exclude filterset, it
// will not be downloaded, and the object will remain a pointer on disk, as if
@ -35,13 +36,17 @@ var (
func smudge(to io.Writer, from io.Reader, filename string, skip bool, filter *filepathfilter.Filter) error {
ptr, pbuf, perr := lfs.DecodeFrom(from)
if perr != nil {
if _, err := tools.Spool(to, pbuf); err != nil {
n, err := tools.Spool(to, pbuf)
if err != nil {
return errors.Wrap(err, perr.Error())
}
return errors.NewNotAPointerError(errors.Errorf(
"Unable to parse pointer at: %q", filename,
))
if n != 0 {
return errors.NewNotAPointerError(errors.Errorf(
"Unable to parse pointer at: %q", filename,
))
}
return nil
}
lfs.LinkOrCopyFromReference(ptr.Oid, ptr.Size)

@ -53,3 +53,35 @@ begin_test "malformed pointers"
popd >/dev/null
)
end_test
begin_test "empty pointers"
(
set -e
reponame="empty-pointers"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat"
git add .gitattributes
git commit -m "initial commit"
touch empty.dat
git \
-c "filter.lfs.process=" \
-c "filter.lfs.clean=cat" \
-c "filter.lfs.required=false" \
add empty.dat
git commit -m "add empty pointer"
git push origin master
pushd .. >/dev/null
clone_repo "$reponame" "$reponame-assert"
[ "0" -eq "$(grep -c "empty.dat" clone.log)" ]
[ "0" -eq "$(wc -c < empty.dat)" ]
popd >/dev/null
)
end_test