Corrected some problems with revision_id() before an initial commit.
authorW. Trevor King <wking@drexel.edu>
Wed, 29 Jul 2009 19:49:45 +0000 (15:49 -0400)
committerW. Trevor King <wking@drexel.edu>
Wed, 29 Jul 2009 19:49:45 +0000 (15:49 -0400)
libbe/git.py
libbe/hg.py
libbe/rcs.py

index 2b45679fdcad7aa7e225ca87673030206e836ce4..f7e96463c4734db509770ab72cda18f193b69971 100644 (file)
@@ -117,7 +117,12 @@ class Git(RCS):
         return full_revision
     def _rcs_revision_id(self, index):
         args = ["rev-list", "--first-parent", "--reverse", "HEAD"]
-        status,output,error = self._u_invoke_client(*args)
+        kwargs = {"expect":(0,128)}
+        status,output,error = self._u_invoke_client(*args, **kwargs)
+        if status == 128:
+            if error.startswith("fatal: ambiguous argument 'HEAD': unknown "):
+                return None
+            raise rcs.CommandError(args, status, error)
         commits = output.splitlines()
         try:
             return commits[index]
index fcda829f8305fa85f34746a26c6b5dd0c94342ac..31df1d0c90ca2a10c8ae50b081cb2886bb2a1922 100644 (file)
@@ -86,7 +86,10 @@ class Hg(RCS):
         kwargs = {"expect": (0,255)}
         status,output,error = self._u_invoke_client(*args, **kwargs)
         if status == 0:
-            return output.strip()
+            id = output.strip()
+            if id == '000000000000':
+                return None # before initial commit.
+            return id
         return None
 
 \f    
index d979df03563af586e978db3cbb0ffc936422f6cb..fdbb01adbd436cd2d88abafcee3d98451d70406c 100644 (file)
@@ -860,6 +860,15 @@ class RCS_commit_TestCase(RCSTestCase):
         self.failUnlessEqual(self.rcs.revision_id(i), None)
         self.failUnlessEqual(self.rcs.revision_id(-i-1), None)
 
+    def test_revision_id_as_committed(self):
+        """Check revision id before first commit"""
+        if not self.rcs.versioned:
+            self.failUnlessEqual(self.rcs.revision_id(5), None)
+            return
+        committed_revisions = []
+        for path in self.test_files:
+            self.failUnlessEqual(self.rcs.revision_id(0), None)
+
 
 class RCS_duplicate_repo_TestCase(RCSTestCase):
     """Test cases for RCS.duplicate_repo method."""