Browse Source

Support ignored argument to dulwich.porcelain.status.

Jelmer Vernooij 7 years ago
parent
commit
aacd6b74f9
3 changed files with 17 additions and 8 deletions
  1. 5 2
      NEWS
  2. 9 6
      dulwich/porcelain.py
  3. 3 0
      dulwich/tests/test_porcelain.py

+ 5 - 2
NEWS

@@ -21,9 +21,12 @@
 
   * Add basic support for reading ignore files in ``dulwich.ignore``.
     ``dulwich.porcelain.add`` and ``dulwich.porcelain.status`` now honor
-   ignores. (Jelmer Vernooij, #524)
+   ignores. (Jelmer Vernooij, Segev Finer, #524)
 
- * New ``dulwich.porcelain.check_ignore`` command.
+  * New ``dulwich.porcelain.check_ignore`` command.
+   (Jelmer Vernooij)
+
+  * ``dulwich.porcelain.status`` now supports a ``ignored`` argument.
    (Jelmer Vernooij)
 
  DOCUMENTATION

+ 9 - 6
dulwich/porcelain.py

@@ -759,16 +759,16 @@ def pull(repo, remote_location=None, refspecs=None,
         r.reset_index(tree=tree)
 
 
-def status(repo="."):
+def status(repo=".", ignored=False):
     """Returns staged, unstaged, and untracked changes relative to the HEAD.
 
     :param repo: Path to repository or repository object
+    :param ignored: Whether to include ignoed files in `untracked`
     :return: GitStatus tuple,
         staged -    list of staged paths (diff index/HEAD)
         unstaged -  list of unstaged paths (diff index/working-tree)
         untracked - list of untracked, un-ignored & non-.git paths
     """
-    # TODO(jelmer): support --ignored
     with open_repo_closing(repo) as r:
         # 1. Get status of staged
         tracked_changes = get_tree_changes(r)
@@ -776,10 +776,13 @@ def status(repo="."):
         index = r.open_index()
         unstaged_changes = list(get_unstaged_changes(index, r.path))
         ignore_manager = IgnoreFilterManager.from_repo(r)
-        untracked_changes = [
-                p for p in
-                get_untracked_paths(r.path, r.path, index)
-                if not ignore_manager.is_ignored(p)]
+        untracked_paths = get_untracked_paths(r.path, r.path, index)
+        if ignored:
+            untracked_changes = list(untracked_paths)
+        else:
+            untracked_changes = [
+                    p for p in untracked_paths
+                    if not ignore_manager.is_ignored(p)]
         return GitStatus(tracked_changes, unstaged_changes, untracked_changes)
 
 

+ 3 - 0
dulwich/tests/test_porcelain.py

@@ -801,6 +801,9 @@ class StatusTests(PorcelainTestCase):
                                               self.repo.open_index())))
         self.assertEqual(set(['.gitignore', 'notignored']),
                          set(porcelain.status(self.repo).untracked))
+        self.assertEqual(set(['.gitignore', 'notignored', 'ignored']),
+                         set(porcelain.status(self.repo, ignored=True)
+                             .untracked))
 
     def test_get_untracked_paths_nested(self):
         with open(os.path.join(self.repo.path, 'notignored'), 'w') as f: