Skip to content

Problem with 0 length files #18

@trenouf

Description

@trenouf

Hi

I have a problem with any file that has an extension that I have marked as being filtered by git-fat, but is zero length. It seems to be clean filtered when it is added to the repository, and smudge filtered when it is checked out, so all correct so far. But then git thinks that the file is dirty, so git status shows it as an unstaged change, and git diff shows a difference where the "old" state is the "#$# git-fat" token and the "new" state is the 0 length file.

Maybe git has some optimization where it decides not to run the smudge filter in some cases when the file is 0 length?

I have a workaround, which is to modify git-fat to do nothing in the clean filter when the file is zero length. Does this seem like a reasonable change?

diff --git a/git-fat b/git-fat
index e62f99b..0d8021a 100755
--- a/git-fat
+++ b/git-fat
@@ -244,7 +244,14 @@ class GitFat(object):
                     os.rename(tmpname, objfile)
                     self.verbose('git-fat filter-clean: caching to %s' % objfile)
                 cached = True
-                outstreamclean.write(self.encode(digest, bytes))
+                # Only write hash if the original file is not 0 length. If it
+                # is 0 length, just leave a 0 length file. This works around
+                # an apparent git problem where it thinks the working tree is
+                # dirty if the smudge filter generates a 0 length file.
+                if bytes != 0:
+                    outstreamclean.write(self.encode(digest, bytes))
+                else:
+                    self.verbose('git-fat filter-clean: not modifying 0 length file')
         finally:
             if not cached:
                 os.remove(tmpname)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions