Browse Source

Implement dulwich.porcelain.ls_files, avoid digraph in setup.cfg.

Jelmer Vernooij 6 years ago
parent
commit
1b6509fa3d
5 changed files with 45 additions and 1 deletions
  1. 10 0
      NEWS
  2. 10 0
      bin/dulwich
  3. 7 0
      dulwich/porcelain.py
  4. 15 0
      dulwich/tests/test_porcelain.py
  5. 3 1
      setup.cfg

+ 10 - 0
NEWS

@@ -1,5 +1,15 @@
 0.19.4	UNRELEASED
 
+ IMPROVEMENTS
+
+  * Add ``porcelain.ls_files``. (Jelmer Vernooij)
+
+ BUG FIXES
+
+  * Avoid unicode characters (e.g. the digraph ij in my surname) in setup.cfg,
+    since setuptools doesn't deal well with them. See
+    https://github.com/pypa/setuptools/issues/1062. (Jelmer Vernooij, #637)
+
 0.19.3	2018-06-17
 
  IMPROVEMENTS

+ 10 - 0
bin/dulwich

@@ -605,6 +605,15 @@ class cmd_stash(SuperCommand):
     }
 
 
+class cmd_ls_files(Command):
+
+    def run(self, args):
+        parser = optparse.OptionParser()
+        options, args = parser.parse_args(args)
+        for name in porcelain.ls_files('.'):
+            print(name)
+
+
 class cmd_help(Command):
 
     def run(self, args):
@@ -646,6 +655,7 @@ commands = {
     "help": cmd_help,
     "init": cmd_init,
     "log": cmd_log,
+    "ls-files": cmd_ls_files,
     "ls-remote": cmd_ls_remote,
     "ls-tree": cmd_ls_tree,
     "pack-objects": cmd_pack_objects,

+ 7 - 0
dulwich/porcelain.py

@@ -33,6 +33,7 @@ Currently implemented:
  * diff-tree
  * fetch
  * init
+ * ls-files
  * ls-remote
  * ls-tree
  * pull
@@ -1282,3 +1283,9 @@ def stash_pop(repo):
         from dulwich.stash import Stash
         stash = Stash.from_repo(r)
         stash.pop()
+
+
+def ls_files(repo):
+    """List all files in an index."""
+    with open_repo_closing(repo) as r:
+        return sorted(r.open_index())

+ 15 - 0
dulwich/tests/test_porcelain.py

@@ -1247,6 +1247,21 @@ class LsRemoteTests(PorcelainTestCase):
             porcelain.ls_remote(self.repo.path))
 
 
+class LsFilesTests(PorcelainTestCase):
+
+    def test_empty(self):
+        self.assertEqual([], list(porcelain.ls_files(self.repo)))
+
+    def test_simple(self):
+        # Commit a dummy file then modify it
+        fullpath = os.path.join(self.repo.path, 'foo')
+        with open(fullpath, 'w') as f:
+            f.write('origstuff')
+
+        porcelain.add(repo=self.repo.path, paths=[fullpath])
+        self.assertEqual([b'foo'], list(porcelain.ls_files(self.repo)))
+
+
 class RemoteAddTests(PorcelainTestCase):
 
     def test_new(self):

+ 3 - 1
setup.cfg

@@ -1,6 +1,8 @@
 [metadata]
 name = dulwich
-author = Jelmer Vernooij
+# Avoid unicode characters, because setuptools doesn't
+# like them. See https://github.com/pypa/setuptools/issues/1062
+author = Jelmer Vernooij
 author_email = jelmer@jelmer.uk
 home-page = https://www.dulwich.io/
 description = file:README.md