Explorar el Código

Add support for recursive add.

Patch by Ryan Faulkner with modifications by me to support recursive
add.
Jelmer Vernooij hace 11 años
padre
commit
4bcd7a822d
Se han modificado 3 ficheros con 36 adiciones y 6 borrados
  1. 3 0
      NEWS
  2. 11 2
      dulwich/porcelain.py
  3. 22 4
      dulwich/tests/test_porcelain.py

+ 3 - 0
NEWS

@@ -2,6 +2,9 @@
 
  IMPROVEMENTS
 
+ * Add support for recursive add in 'git add'.
+   (Ryan Faulkner, Jelmer Vernooij)
+
  * Add porcelain 'list_tags'. (Ryan Faulkner)
 
  * Add porcelain 'push'. (Ryan Faulkner)

+ 11 - 2
dulwich/porcelain.py

@@ -194,10 +194,19 @@ def add(repo=".", paths=None):
     """Add files to the staging area.
 
     :param repo: Repository for the files
-    :param paths: Paths to add
+    :param paths: Paths to add.  No value passed stages all modified files.
     """
-    # FIXME: Support patterns, directories, no argument.
+    # FIXME: Support patterns, directories.
     r = open_repo(repo)
+    if not paths:
+        # If nothing is specified, add all non-ignored files.
+        paths = []
+        for dirpath, dirnames, filenames in os.walk(r.path):
+            # Skip .git and below.
+            if '.git' in dirnames:
+                dirnames.remove('.git')
+            for filename in filenames:
+                paths.append(os.path.join(dirpath[len(r.path)+1:], filename))
     r.stage(paths)
 
 

+ 22 - 4
dulwich/tests/test_porcelain.py

@@ -179,12 +179,30 @@ 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")
+        porcelain.add(repo=self.repo.path, paths=['blah'])
+        porcelain.commit(repo=self.repo.path, message='test',
+            author='test', committer='test')
+
+        # Add a second test file and a file in a directory
+        with open(os.path.join(self.repo.path, 'foo'), 'w') as f:
+            f.write("\n")
+        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)
+
+        # Check that foo was added and nothing in .git was modified
+        index = self.repo.open_index()
+        self.assertEquals(list(index), ['blah', 'foo', 'adir/afile'])
+
     def test_add_file(self):
-        f = open(os.path.join(self.repo.path, 'foo'), 'w')
-        try:
+        with open(os.path.join(self.repo.path, 'foo'), 'w') as f:
             f.write("BAR")
-        finally:
-            f.close()
         porcelain.add(self.repo.path, paths=["foo"])