``dulwich.porcelain.add`` now honors ignores.
(Jelmer Vernooij, #524)
+ * New ``dulwich.porcelain.check_ignore`` command.
+ (Jelmer Vernooij)
+
DOCUMENTATION
* Clarified docstrings for Client.{send_pack,fetch_pack} implementations.
return cmd_kls(args[1:])
+class cmd_check_ignore(Command):
+
+ def run(self, args):
+ parser = optparse.OptionParser()
+ options, args = parser.parse_args(args)
+ for path in porcelain.check_ignore('.', args):
+ print(path)
+
+
class cmd_help(Command):
def run(self, args):
commands = {
"add": cmd_add,
"archive": cmd_archive,
+ "check-ignore": cmd_check_ignore,
"clone": cmd_clone,
"commit": cmd_commit,
"commit-tree": cmd_commit_tree,
* archive
* add
* branch{_create,_delete,_list}
+ * check-ignore
* clone
* commit
* commit-tree
raise RemoteExists(section)
c.set(section, b"url", url)
c.write_to_path()
+
+
+def check_ignore(repo, paths, no_index=False):
+ """Debug gitignore files.
+
+ :param repo: Path to the repository
+ :param paths: List of paths to check for
+ :param no_index: Don't check index
+ :return: List of ignored files
+ """
+ with open_repo_closing(repo) as r:
+ index = r.open_index()
+ ignore_manager = IgnoreFilterManager.from_repo(r)
+ for path in paths:
+ if os.path.isdir(path):
+ continue
+ if os.path.isabs(path):
+ path = os.path.relpath(path, r.path)
+ if (not no_index and
+ path.encode(sys.getfilesystemencoding()) in index):
+ continue
+ if ignore_manager.is_ignored(path):
+ yield path
self.repo, 'jelmer', 'git://jelmer.uk/code/dulwich')
self.assertRaises(porcelain.RemoteExists, porcelain.remote_add,
self.repo, 'jelmer', 'git://jelmer.uk/code/dulwich')
+
+
+class CheckIgnoreTests(PorcelainTestCase):
+
+ def test_check_ignored(self):
+ with open(os.path.join(self.repo.path, '.gitignore'), 'w') as f:
+ f.write("foo")
+ with open(os.path.join(self.repo.path, 'foo'), 'w') as f:
+ f.write("BAR")
+ with open(os.path.join(self.repo.path, 'bar'), 'w') as f:
+ f.write("BAR")
+ self.assertEqual(
+ ['foo'],
+ list(porcelain.check_ignore(self.repo, ['foo'])))
+ self.assertEqual([], list(porcelain.check_ignore(self.repo, ['bar'])))
+
+ def test_check_added(self):
+ with open(os.path.join(self.repo.path, 'foo'), 'w') as f:
+ f.write("BAR")
+ self.repo.stage(['foo'])
+ with open(os.path.join(self.repo.path, '.gitignore'), 'w') as f:
+ f.write("foo\n")
+ self.assertEqual(
+ [], list(porcelain.check_ignore(self.repo, ['foo'])))
+ self.assertEqual(
+ ['foo'],
+ list(porcelain.check_ignore(self.repo, ['foo'], no_index=True)))