diff options
author | masklinn <bitbucket.org@masklinn.net> | 2014-03-11 10:09:07 +0100 |
---|---|---|
committer | masklinn <bitbucket.org@masklinn.net> | 2014-03-11 10:09:07 +0100 |
commit | 897b707bc1208793b7f63dd28d9167b2ce7ab766 (patch) | |
tree | b0f9dd81a267819bf0adf959856230435415c2d8 | |
parent | 7da2dec0262c803cf8f9814c49f8fb4c6b899b52 (diff) | |
download | python-fastimport-git-897b707bc1208793b7f63dd28d9167b2ce7ab766.tar.gz |
Add basic commit copy test
* don't assume file_iter is a list (though the parser sets one)
* don't copy inferred name attribute
-rw-r--r-- | fastimport/commands.py | 5 | ||||
-rw-r--r-- | fastimport/tests/test_commands.py | 18 |
2 files changed, 22 insertions, 1 deletions
diff --git a/fastimport/commands.py b/fastimport/commands.py index 7ddf0fd..572bd14 100644 --- a/fastimport/commands.py +++ b/fastimport/commands.py @@ -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) diff --git a/fastimport/tests/test_commands.py b/fastimport/tests/test_commands.py index 1259798..12a3772 100644 --- a/fastimport/tests/test_commands.py +++ b/fastimport/tests/test_commands.py @@ -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): |