Browse Source

Provide a rm command in porcelain.

Jelmer Vernooij 11 years ago
parent
commit
6047ead898
3 changed files with 34 additions and 4 deletions
  1. 8 0
      bin/dulwich
  2. 13 0
      dulwich/porcelain.py
  3. 13 4
      dulwich/tests/test_porcelain.py

+ 8 - 0
bin/dulwich

@@ -54,6 +54,12 @@ def cmd_add(args):
     porcelain.add(".", paths=args)
 
 
+def cmd_rm(args):
+    opts, args = getopt(args, "", [])
+
+    porcelain.rm(".", paths=args)
+
+
 def cmd_fetch_pack(args):
     opts, args = getopt(args, "", ["all"])
     opts = dict(opts)
@@ -209,6 +215,8 @@ commands = {
     "archive": cmd_archive,
     "update-server-info": cmd_update_server_info,
     "diff": cmd_diff,
+    "add": cmd_add,
+    "rm": cmd_rm
     }
 
 if len(sys.argv) < 2:

+ 13 - 0
dulwich/porcelain.py

@@ -126,3 +126,16 @@ def add(repo=".", paths=None):
     # FIXME: Support patterns, directories, no argument.
     r = open_repo(repo)
     r.stage(paths)
+
+
+def rm(repo=".", paths=None):
+    """Remove files from the staging area.
+
+    :param repo: Repository for the files
+    :param paths: Paths to remove
+    """
+    r = open_repo(repo)
+    index = r.open_index()
+    for p in paths:
+        del index[p]
+    index.write()

+ 13 - 4
dulwich/tests/test_porcelain.py

@@ -25,9 +25,6 @@ import tarfile
 import tempfile
 
 from dulwich import porcelain
-from dulwich.porcelain import (
-    update_server_info,
-    )
 from dulwich.repo import Repo
 from dulwich.tests.utils import (
     make_object,
@@ -120,4 +117,16 @@ class AddTests(PorcelainTestCase):
             f.write("BAR")
         finally:
             f.close()
-        porcelain.add(".", paths=["foo"])
+        porcelain.add(self.repo.path, paths=["foo"])
+
+
+class RemoveTests(PorcelainTestCase):
+
+    def test_remove_file(self):
+        f = open(os.path.join(self.repo.path, 'foo'), 'w')
+        try:
+            f.write("BAR")
+        finally:
+            f.close()
+        porcelain.add(self.repo.path, paths=["foo"])
+        porcelain.rm(self.repo.path, paths=["foo"])