Don't create LFS pointer for empty files #966
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes the reported behaviour in #557, where Git reports
a delta, if an attempt was made to track empty files with LFS.
If there already have been empty files tracked with LFS, these
need to be untracked manually, as this fix only prevents that
newly created, empty files can be tracked by LFS.
Problem is, that Git never runs the clean filter on 0-byte files:
https://github.com/git/git/blob/80980a1d5c2678ab9031d7c60faf38b9631eb1ce/diff.c#L2777
This leads to a diff between the file in the repository (pointer file) and
the actual file content. Apparently the git-fat project seems to be affected
by this, too (jedbrown/git-fat#18).
The fix/workaround for this in LFS is simple; just don't create pointers
for 0-byte target files, it's useless to store them in LFS anyway.
I'm not too sure though if my current patch is sufficient - it just checks
if the given file from the parameters has a size == 0, but apparently the
pointer creation + hash calculation is done from the stdin content. So just
let me know if this needs a rework with length calculation of the stdin
io.Reader.