Commits

eug48 committed cfc734a

support for specifying a commit date in hg_commit

Comments (0)

Files changed (2)

         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, date=None, files=[], close_branch=False):
         """Commit changes to the repository."""
         userspec = "-u" + user if user else "-u" + self.user if self.user else ""
+        datespec = "-d" + date if date else ""
         close = "--close-branch" if close_branch else ""
-        args = [close, userspec] + files
+        args = [close, userspec, datespec] + files
         # don't send a "" arg for userspec or close, which HG will
         # consider the files arg, committing all files instead of what
         # was passed in files kwarg

hgapi/testhgapi.py

         branch_names = self.repo.get_branch_names()
         self.assertEquals(len(branch_names), 2)
 
+    def test_200_CommitWithDates(self):
+        rev0 = self.repo.hg_rev()
+
+        with open("test/file.txt", "w+") as out:
+            out.write("even more stuff")
+
+        self.repo.hg_commit("modifying and setting a date", user="test", date="10/10/11 UTC")
+
+        rev = self.repo["tip"]
+        self.assertEquals(rev.desc, "modifying and setting a date")
+        self.assertEquals(rev.author, "test")
+        self.assertEquals(rev.branch, "test_branch")
+        self.assertEquals(rev.date, "2011-10-10 00:00 +0000")
+        self.assertEquals(rev.parents, [rev0])
+
 def test_doc():
     #Prepare for doctest
     os.mkdir("./test_hgapi")