Commits

Fredrik Håård committed f1d7e87

Added status command (ticket #6)

  • Participants
  • Parent commits 838c86d

Comments (0)

Files changed (3)

File hgapi/hgapi.py

         """Add a file to the repo"""
         self.hg_command("add", filepath)
 
+    def hg_remove(self, filepath):
+        """Remove a file from the repo"""
+        self.hg_command("remove", filepath)
+
     def hg_update(self, reference):
         """Update to the revision indetified by reference"""
         self.hg_command("update", str(reference))
                 cmds += [key, kwargs[key]]
         return self.hg_command(*cmds)
         
+    def hg_status(self):
+        cmds = ['status']
+        out = self.hg_command(*cmds).strip()
+        if not out: return {}
+        lines = out.split("\n")
+        status_split = re.compile("^(.) (.*)$")
+        changes = {}
+        for change, path in [status_split.match(x).groups() for x in lines]:
+            changes.setdefault(change, []).append(path)
+        return changes
+        
     rev_log_tpl = '\{"node":"{node|short}","rev":"{rev}","author":"{author|urlescape}","branch":"{branch}", "parents":"{parents}","date":"{date|isodate}","tags":"{tags}","desc":"{desc|urlescape}"}'        
 
     def revision(self, identifier):

File hgapi/testhgapi.py

         self.assertEquals(self.repo["tip"].desc, "}")
         self.assertEquals(self.repo["tip"].author, "},desc=\"test")
   
+
+    def test_090_ModifiedStatus(self):
+        #write some more to file
+        with open("test/file.txt", "a") as out:
+            out.write("stuff stuff stuff")
+        status = self.repo.hg_status()
+        self.assertEquals(status, {'M': ['file.txt']})
+
+    def test_100_CleanStatus(self):
+        #commit file created in 090
+        self.repo.hg_commit("Comitting changes", user="test")
+        #Assert status is empty
+        self.assertEquals(self.repo.hg_status(), {})
+
+    def test_110_UntrackedStatus(self):
+        #Create a new file
+        with open("test/file2.txt", "w") as out:
+            out.write("stuff stuff stuff")
+        status = self.repo.hg_status()
+        self.assertEquals(status, {'?': ['file2.txt']})
+
+    def test_120_AddedStatus(self):
+        #Add file created in 110
+        self.repo.hg_add("file2.txt")
+        status = self.repo.hg_status()
+        self.assertEquals(status, {'A': ['file2.txt']})
+
+    def test_130_MissingStatus(self):
+        #Commit file created in 120
+        self.repo.hg_commit("Added file")
+        import os
+        os.unlink("test/file2.txt")
+        status = self.repo.hg_status()
+        self.assertEquals(status, {'!': ['file2.txt']})
+
+    def test_140_RemovedStatus(self):
+        #Remove file from repo
+        self.repo.hg_remove("file2.txt")
+        status = self.repo.hg_status()
+        self.assertEquals(status, {'R': ['file2.txt']})
+
+
 def test_doc():
     os.mkdir("./test_hgapi")
     with open("test_hgapi/file.txt", "w") as target:
 
 setup(
     name = "hgapi",
-    version = "1.0.1",
+    version = "1.1.0c1",
     packages = ['hgapi'],
-    test_suite = "testhgapi.TestHgAPI",
+    test_suite = "hgapi.testhgapi.TestHgAPI",
 
     # metadata
     author = u"Fredrik Håård",