Просмотр исходного кода

Make `porcelain.add` check explicit for `None` (#2027)

https://github.com/jelmer/dulwich/issues/2018
Jelmer Vernooij 1 месяц назад
Родитель
Сommit
c485e66c2b
2 измененных файлов с 13 добавлено и 1 удалено
  1. 1 1
      dulwich/porcelain.py
  2. 12 0
      tests/test_porcelain.py

+ 1 - 1
dulwich/porcelain.py

@@ -1485,7 +1485,7 @@ def add(
             get_unstaged_changes(index, r.path, filter_callback, preload_index)
             get_unstaged_changes(index, r.path, filter_callback, preload_index)
         )
         )
 
 
-        if not paths:
+        if paths is None:
             # When no paths specified, add all untracked and modified files from repo root
             # When no paths specified, add all untracked and modified files from repo root
             paths = [str(repo_path)]
             paths = [str(repo_path)]
         relpaths = []
         relpaths = []

+ 12 - 0
tests/test_porcelain.py

@@ -2139,6 +2139,18 @@ class AddTests(PorcelainTestCase):
         self.assertIn(b"existing.txt", index)
         self.assertIn(b"existing.txt", index)
         self.assertIn(b"new.txt", index)
         self.assertIn(b"new.txt", index)
 
 
+    def test_add_empty_paths_list(self) -> None:
+        """Test that passing paths=[] does not add any files."""
+        # Create an untracked file
+        with open(os.path.join(self.repo.path, "file.txt"), "w") as f:
+            f.write("content")
+
+        # Add with empty paths list
+        added, _ignored = porcelain.add(self.repo.path, paths=[])
+
+        # Should not add any files
+        self.assertEqual(len(added), 0)
+
 
 
 class RemoveTests(PorcelainTestCase):
 class RemoveTests(PorcelainTestCase):
     def test_remove_file(self) -> None:
     def test_remove_file(self) -> None: