diff options
authorTodd Zullinger <>2010-09-08 10:12:31 -0400
committerJesse Keating <>2010-09-08 16:23:19 -0700
commit658937cded0f763e751bce4f2f60c49199fd14ce (patch)
parent61b297252e5e468cb80ade9b72dcc62132373a8c (diff)
fedpkg: Try not to add redundant gitignore entries
If there is a entry which matches the filename we're about to add already in the gitignore file, we don't need to bother adding another entry. This adds a match() method to GitIgnore which uses fnmatch. Under the hood, this is what git uses. It doesn't catch some of the special cases git has, but it should simply fail to match in those cases and will add a potentially redundant entry -- no different than previously.
1 files changed, 11 insertions, 1 deletions
diff --git a/src/pyfedpkg/ b/src/pyfedpkg/
index 65e64bc..62a5654 100644
--- a/src/pyfedpkg/
+++ b/src/pyfedpkg/
@@ -27,6 +27,7 @@ import ConfigParser
import stat
import StringIO
import OpenSSL
+import fnmatch
# Define some global variables, put them here to make it easy to change
@@ -840,6 +841,14 @@ class GitIgnore(object):
self.modified = True
+ def match(self, line):
+ line = line.lstrip('/').rstrip('\n')
+ for entry in self.__lines:
+ entry = entry.lstrip('/').rstrip('\n')
+ if fnmatch.fnmatch(line, entry):
+ return True
+ return False
def write(self):
""" Write the new .gitignore file if any modifications were made. """
if self.modified:
@@ -1437,7 +1446,8 @@ class PackageModule:
sources_file.write("%s %s\n" % (file_hash, file_basename))
# Add this file to .gitignore if it's not already there:
- gitignore.add('/%s' % file_basename)
+ if not gitignore.match(file_basename):
+ gitignore.add('/%s' % file_basename)
if lookaside.file_exists(self.module, file_basename, file_hash):
# Already uploaded, skip it: