ソースを参照

In ``dulwich.porcelain.add``, if no files are specified,
add from current working directory rather than repository root.
Closes #521

Jelmer Vernooij 7 年 前
コミット
c4eaba1ba8
3 ファイル変更30 行追加3 行削除
  1. 4 0
      NEWS
  2. 1 1
      dulwich/porcelain.py
  3. 25 2
      dulwich/tests/test_porcelain.py

+ 4 - 0
NEWS

@@ -10,6 +10,10 @@
   * Pass 'mkdir' argument onto Repo.init_bare in Repo.clone.
     (Jelmer Vernooij, #504)
 
+  * In ``dulwich.porcelain.add``, if no files are specified,
+   add from current working directory rather than repository root.
+   (Jelmer Vernooij, #521)
+
  DOCUMENTATION
 
   * Clarified docstrings for Client.{send_pack,fetch_pack} implementations.

+ 1 - 1
dulwich/porcelain.py

@@ -317,7 +317,7 @@ def add(repo=".", paths=None):
         if not paths:
             # If nothing is specified, add all non-ignored files.
             paths = []
-            for dirpath, dirnames, filenames in os.walk(r.path):
+            for dirpath, dirnames, filenames in os.walk(os.getcwd()):
                 # Skip .git and below.
                 if '.git' in dirnames:
                     dirnames.remove('.git')

+ 25 - 2
dulwich/tests/test_porcelain.py

@@ -224,7 +224,6 @@ class InitTests(TestCase):
 class AddTests(PorcelainTestCase):
 
     def test_add_default_paths(self):
-
         # create a file for initial commit
         with open(os.path.join(self.repo.path, 'blah'), 'w') as f:
             f.write("\n")
@@ -238,12 +237,36 @@ class AddTests(PorcelainTestCase):
         os.mkdir(os.path.join(self.repo.path, 'adir'))
         with open(os.path.join(self.repo.path, 'adir', 'afile'), 'w') as f:
             f.write("\n")
-        porcelain.add(self.repo.path)
+        cwd = os.getcwd()
+        try:
+            os.chdir(self.repo.path)
+            porcelain.add(self.repo.path)
+        finally:
+            os.chdir(cwd)
 
         # Check that foo was added and nothing in .git was modified
         index = self.repo.open_index()
         self.assertEqual(sorted(index), [b'adir/afile', b'blah', b'foo'])
 
+    def test_add_default_paths_subdir(self):
+        os.mkdir(os.path.join(self.repo.path, 'foo'))
+        with open(os.path.join(self.repo.path, 'blah'), 'w') as f:
+            f.write("\n")
+        with open(os.path.join(self.repo.path, 'foo', 'blie'), 'w') as f:
+            f.write("\n")
+
+        cwd = os.getcwd()
+        try:
+            os.chdir(os.path.join(self.repo.path, 'foo'))
+            porcelain.add(repo=self.repo.path)
+            porcelain.commit(repo=self.repo.path, message=b'test',
+                author=b'test', committer=b'test')
+        finally:
+            os.chdir(cwd)
+
+        index = self.repo.open_index()
+        self.assertEqual(sorted(index), [b'foo/blie'])
+
     def test_add_file(self):
         with open(os.path.join(self.repo.path, 'foo'), 'w') as f:
             f.write("BAR")