Add basic commit copy test
authormasklinn <bitbucket.org@masklinn.net>
Tue, 11 Mar 2014 09:09:07 +0000 (10:09 +0100)
committermasklinn <bitbucket.org@masklinn.net>
Tue, 11 Mar 2014 09:09:07 +0000 (10:09 +0100)
* don't assume file_iter is a list (though the parser sets one)
* don't copy inferred name attribute

fastimport/commands.py
fastimport/tests/test_commands.py

index 7ddf0fda264c508f22b083e015a412138e6b2238..572bd14de51532810755a751095a4b4b6369ce51 100644 (file)
@@ -143,8 +143,11 @@ class CommitCommand(ImportCommand):
             self.id = ':%s' % mark
 
     def copy(self, **kwargs):
+        if not isinstance(self.file_iter, list):
+            self.file_iter = list(self.file_iter)
+
         fields = dict((k, v) for k, v in self.__dict__.iteritems()
-                      if k != 'id'
+                      if k not in ('id', 'name')
                       if not k.startswith('_'))
         fields.update(kwargs)
         return CommitCommand(**fields)
index 12597987f54678722000290f0fdebd499f49f4e0..12a3772b52ae22c71a0d5601321bf2edc51c88ca 100644 (file)
@@ -197,6 +197,24 @@ class TestCommitDisplay(TestCase):
             "property planet 5 world",
             repr(c))
 
+class TestCommitCopy(TestCase):
+    def setUp(self):
+        super(TestCommitCopy, self).setUp()
+        file_cmds = iter([
+            commands.FileDeleteCommand('readme.txt'),
+            commands.FileModifyCommand('NEWS', 0100644, None, 'blah blah blah'),
+        ])
+        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
+        committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
+        self.c = commands.CommitCommand(
+            "refs/heads/master", "bbb", None, committer,
+            "release v1.0", ":aaa", None, file_cmds)
+
+    def test_noop(self):
+        c2 = self.c.copy()
+
+        self.assertIsNot(self.c, c2)
+        self.assertEqual(repr(self.c), repr(c2))
 
 class TestFeatureDisplay(TestCase):