You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an empty file I'd like LFS to track so that I can test whether LFS is set up properly during the build. However, LFS seems to ignore the attribute for empty (or too small?) files.
Most of the LFS test cases are for really tiny files. We even have a test dedicated to empty files. However, LFS essentially passes empty files through, so they still result in empty Git blobs. The smallest pointer that LFS can generate is for a 1 byte file.
diff --git a/1.bin b/1.bin
new file mode 100644
index 0000000..55180c0
--- /dev/null+++ b/1.bin@@ -0,0 +1,3 @@+version https://git-lfs.github.com/spec/v1+oid sha256:6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b+size 1
What files are you adding? What does your .gitattributes look like?
I'm trying to add an empty file so that our build system can detect whether LFS was actually used before adding tests which would otherwise read the raw pointer files and fail. The "small content" file I tried was writing LFS sentinel\n to a file; it went through untouched. This is the commit which adds the file LFS is ignoring (the small content test was done by git commit --amend on that file, so maybe there's something going wrong there?).
IMO, if filter=lfs is used, LFS should do its thing and make a pointer file. Where in the spec does it specify that an empty file is a valid LFS pointer?
Keep in mind that .gitattributes changes only take affect on files that are added through git add or git commit -aafter the change. It's up to Git to call LFS based on those matched patterns. We have no control over when that happens. Is it possible the LFS sentinel file was added before the .gitattributes?
The git tree shows a literal empty file. When trying to checkout this branch, I see this:
Pointer file error: Unable to parse pointer at: "data/cmb-data"
So even LFS doesn't like the literal empty file. I conclude that LFS really should turn it into a pointer since it doesn't pass an empty file through on the smudge side of the filtering.
I'm unable to replicate that error. What version of LFS are you using? If you can replicate that error in the test on the latest Git LFS release, that'd really help track this down. I agree that LFS should work with empty files.
EDIT: To be clear, LFS should work with empty files. I don't think they need to be added to the Git repository as an LFS pointer though. It just seems wasteful. Adding a non-empty file for testing seems reasonable to me.
It was easier to test for empty content rather than a specific string, but then I hit this. Hmm, it looks like I may have gotten LFS a while ago; I'm using 1.5.5 on that machine.
Cool. That looks correct to me. IIRC, there was some other issue with zero length blobs, and the fix was basically passing them through to Git. Sounds like you were just on an old version of LFS.
Does it mean an empty file is supposed to be actually stored in LFS?
Is git lfs ls-files expected to list an empty file?
I think the answer is two "no"s here: the pointer representation of an empty file is the empty file (for historical reasons, perhaps we would do it differently today). Since the representation is idempotent, it's the case that Git LFS does not pay attention to the file at all, e.g., it does not show up in the list of git lfs ls-files, or be stored in .git/lfs/objects, etc.
The statement was added in response to the current behavior of git-lfs (I wanted size 0 to be a thing, but the implementation did not behave that way). It seems that behavior has changed around this (lack of test coverage?).
Activity
mathstuf commentedon Jul 27, 2017
Yeah, files with little content are also skipped.
technoweenie commentedon Jul 28, 2017
Most of the LFS test cases are for really tiny files. We even have a test dedicated to empty files. However, LFS essentially passes empty files through, so they still result in empty Git blobs. The smallest pointer that LFS can generate is for a 1 byte file.
What files are you adding? What does your
.gitattributeslook like?mathstuf commentedon Jul 28, 2017
I'm trying to add an empty file so that our build system can detect whether LFS was actually used before adding tests which would otherwise read the raw pointer files and fail. The "small content" file I tried was writing
LFS sentinel\nto a file; it went through untouched. This is the commit which adds the file LFS is ignoring (the small content test was done bygit commit --amendon that file, so maybe there's something going wrong there?).IMO, if
filter=lfsis used, LFS should do its thing and make a pointer file. Where in the spec does it specify that an empty file is a valid LFS pointer?Here is the
.gitattributeschange commit (it works for all other files under that directory).technoweenie commentedon Jul 28, 2017
Hmm, it worked fine for me. I tried adding your .gitattributes changes, and creating a couple dummy files:
Keep in mind that
.gitattributeschanges only take affect on files that are added throughgit addorgit commit -aafter the change. It's up to Git to call LFS based on those matched patterns. We have no control over when that happens. Is it possible the LFS sentinel file was added before the.gitattributes?mathstuf commentedon Jul 28, 2017
The
~2commit of the sentinel file is the attributes change.mathstuf commentedon Jul 28, 2017
Running under
GIT_TRACE=1and adding thatcmb-datafile:The git tree shows a literal empty file. When trying to checkout this branch, I see this:
So even LFS doesn't like the literal empty file. I conclude that LFS really should turn it into a pointer since it doesn't pass an empty file through on the smudge side of the filtering.
technoweenie commentedon Jul 28, 2017
I'm unable to replicate that error. What version of LFS are you using? If you can replicate that error in the test on the latest Git LFS release, that'd really help track this down. I agree that LFS should work with empty files.
EDIT: To be clear, LFS should work with empty files. I don't think they need to be added to the Git repository as an LFS pointer though. It just seems wasteful. Adding a non-empty file for testing seems reasonable to me.
mathstuf commentedon Jul 28, 2017
It was easier to test for empty content rather than a specific string, but then I hit this. Hmm, it looks like I may have gotten LFS a while ago; I'm using 1.5.5 on that machine.
mathstuf commentedon Jul 28, 2017
With 2.2.1:
mathstuf commentedon Jul 28, 2017
Here's something a bit more structured and from the start:
Also, fun…LFS's test suite modifies the global git configuration. Glad I caught that…
technoweenie commentedon Jul 28, 2017
Cool. That looks correct to me. IIRC, there was some other issue with zero length blobs, and the fix was basically passing them through to Git. Sounds like you were just on an old version of LFS.
mathstuf commentedon Jul 28, 2017
OK. Could the spec be updated to indicate that an empty file is also a valid LFS pointer then?
technoweenie commentedon Jul 28, 2017
Sure, that's a great idea for clarification.
spec: mention that an empty file is its own LFS pointer
mloskot commentedon Jan 10, 2019
git-lfs/docs/spec.md
Lines 23 to 24 in 3678c8e
Could anyone clarify the passing through LFS?
git lfs ls-filesexpected to list an empty file?For example, using
empty.binis tracked by LFS, then whygit lfs ls-filesdoes not list it?empty.binis not tracked by LFS, thengit lfs statusis confusing.mathstuf commentedon Jan 10, 2019
Well, you conceptually it is as far as
git-lfsis concerned; it just elides out actually asking for 0 bytes from the server.Hmm. I'd expect that it would since it has the attribute set.
ttaylorr commentedon Jan 26, 2019
I think the answer is two "no"s here: the pointer representation of an empty file is the empty file (for historical reasons, perhaps we would do it differently today). Since the representation is idempotent, it's the case that Git LFS does not pay attention to the file at all, e.g., it does not show up in the list of
git lfs ls-files, or be stored in.git/lfs/objects, etc.mloskot commentedon Jan 27, 2019
@ttaylorr Thanks for the explanation.
slonopotamus commentedon Oct 16, 2019
See #3863. I believe that the statement you added to the spec only harms things because it adds unnecessary special case in git-lfs where bugs hide.
mathstuf commentedon Oct 16, 2019
The statement was added in response to the current behavior of
git-lfs(I wantedsize 0to be a thing, but the implementation did not behave that way). It seems that behavior has changed around this (lack of test coverage?).