Commits

Fredrik Håård committed a04d5f6

Added revert, added empty parameter to status

Comments (0)

Files changed (2)

         """Merge reference to current"""
         self.hg_command("merge", reference)
         
+    def hg_revert(self, all=False, *files):
+        """Revert repository"""
+        
+        if all:
+            cmd = ["revert", "--all"]
+        else:
+            cmd = ["revert"] + list(files)
+        self.hg_command(*cmd)
+
     def hg_node(self):
         """Get the full node id of the current revision"""
         res = self.hg_command("log", "-r", self.hg_id(), "--template", "{node}")
                 cmds += [key, kwargs[key]]
         return self.hg_command(*cmds)
         
-    def hg_status(self):
+    def hg_status(self, empty=False):
         """Get repository status.
         Returns a dict containing a *change char* -> *file list* mapping, where 
         change char is in::
 
          {'A': ['one.txt'], 'M': ['a_folder/two.txt', 'three.txt'],
          '!': [], '?': [], 'R': []}
+
+        If empty is set to non-False value, don't add empty lists
         """
         cmds = ['status']
         out = self.hg_command(*cmds).strip()
         #default empty set
-        changes = {'A': [], 'M': [], '!': [], '?': [], 'R': []}
+        if empty:
+            changes = {}
+        else:
+            changes = {'A': [], 'M': [], '!': [], '?': [], 'R': []}
         if not out: return changes
         lines = out.split("\n")
         status_split = re.compile("^(.) (.*)$")

hgapi/testhgapi.py

                           {'A': [], 'M': [], '!': [], 
                            '?': [], 'R': ['file2.txt']})
 
+    def test_140_EmptyStatus(self):
+        self.repo.hg_revert(all=True)
+        status = self.repo.hg_status(empty=True)
+        self.assertEquals(status, {})
+
     def test_150_ForkAndMerge(self):
         #Store this version
         node = self.repo.hg_node()
         heads = self.repo.hg_heads()
         self.assertEquals(len(heads), 1)
 
-
 def test_doc():
     #Prepare for doctest
     os.mkdir("./test_hgapi")