Commits

Fredrik Håård committed 56bb474

Added merge command

  • Participants
  • Parent commits eaa3135

Comments (0)

Files changed (3)

  hg log
  hg remove
  hg status
+ hg merge<
 
 You also have access to the configuration (config, configbool,
 configlist) just as in the internal Mercurial API.

File hgapi/hgapi.py

         """Remove a file from the repo"""
         self.hg_command("remove", filepath)
 
-    def hg_update(self, reference):
+    def hg_update(self, reference, clean=False):
         """Update to the revision indetified by reference"""
-        self.hg_command("update", str(reference))
+        cmd = ["update", str(reference)]
+        if clean: cmd.append("--clean")
+        self.hg_command(*cmd)
 
     def hg_heads(self):
         """Gets a list with the node id:s of all open heads"""
         res = self.hg_command("heads","--template", "{node}\n")
         return [head for head in res.split("\n") if head]
+
+    def hg_merge(self, reference):
+        """Merge reference to current"""
+        self.hg_command("merge", reference)
         
     def hg_node(self):
         """Get the full node id of the current revision"""
         res = self.hg_command("log", "-r", self.hg_id(), "--template", "{node}")
         return res.strip()
 
-    def hg_commit(self, message, user=None, files=["."], close_branch=False):
+    def hg_commit(self, message, user=None, files=[], close_branch=False):
         """Commit changes to the repository."""
         userspec = "-u" + user if user else "-u" + self.user if self.user else ""
         close = "--close-branch" if close_branch else ""

File hgapi/testhgapi.py

                           {'A': [], 'M': [], '!': [], 
                            '?': [], 'R': ['file2.txt']})
 
+    def test_150_ForkAndMerge(self):
+        #Store this version
+        node = self.repo.hg_node()
+
+        self.repo.hg_update(4, clean=True)
+        with open("test/file3.txt", "w") as out:
+            out.write("this is more stuff")
+
+        #creates new head
+        self.repo.hg_add("file3.txt")
+        self.repo.hg_commit("adding head", user="test")
+
+        heads = self.repo.hg_heads()
+        self.assertEquals(len(heads), 2)
+        self.assertTrue(node in heads)
+        self.assertTrue(self.repo.hg_node() in heads)
+
+        #merge the changes
+        self.repo.hg_merge(node)
+        self.repo.hg_commit("merge")
+        
+        #Check that there's only one head remaining
+        heads = self.repo.hg_heads()
+        self.assertEquals(len(heads), 1)
+
 
 def test_doc():
+    #Prepare for doctest
     os.mkdir("./test_hgapi")
     with open("test_hgapi/file.txt", "w") as target:
         w = target.write("stuff")
-    res = doctest.testfile("../README.rst")
-    shutil.rmtree("test_hgapi")
+    try:
+        #Run doctest
+        res = doctest.testfile("../README.rst")
+    finally:
+        #Cleanup
+        shutil.rmtree("test_hgapi")
 
 if __name__ == "__main__":
-    test_doc()
-    unittest.main()
+    import sys
+    try:
+        test_doc()
+    finally:
+        unittest.main()