lionheart / git-bigstore

Bigstore is a Git extension that helps you track big files in your repositories.
Apache License 2.0
183 stars 28 forks source link

.gitattributes filters with foldernames do not work outside main folder #37

Open calebrottman opened 7 years ago

calebrottman commented 7 years ago

git supports .gitattributes filters with folder names and wildcards (i.e. subpath/**/*.raw filter=bigstore. However, if you are not in the main path and do a git bigstore push, it will silently fail.

This is because in the current version, a fnmatch is called with the base filename and wildcard here. If you are in the folder subpath that contains the file foo.raw, fnmatch will fail because it is comparing subpath/**/*.raw to foo.raw.

This issue should be fixed by replacing the line:

-            if fnmatch.fnmatch(filename, wildcard):
+            full_filename = os.path.join(os.getcwd(), filename)
+            rel_filename = os.path.relpath(full_filename, toplevel_dir)
+            if fnmatch.fnmatch(rel_filename, wildcard):

(I figured this change was too small to do a separate pull request).