diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2014-03-11 11:37:52 +0000 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2014-03-11 11:37:52 +0000 |
commit | 2717e4913afb982d9916e5051789e89f042060c9 (patch) | |
tree | 3925a07acd9ed6de8980b0f04d62ea246dd51a15 | |
parent | a1bc3a35231f657c289b32bd687d14214d6d09a5 (diff) | |
parent | 6b37f5f1de6fb813056fc994cd7fa776996b659e (diff) | |
download | python-fastimport-git-2717e4913afb982d9916e5051789e89f042060c9.tar.gz |
Merge branch 'commit-copy' of git://github.com/masklinn/python-fastimport
-rw-r--r-- | fastimport/commands.py | 10 | ||||
-rw-r--r-- | fastimport/tests/test_commands.py | 29 |
2 files changed, 39 insertions, 0 deletions
diff --git a/fastimport/commands.py b/fastimport/commands.py index 43b1f8f..d83b905 100644 --- a/fastimport/commands.py +++ b/fastimport/commands.py @@ -142,6 +142,16 @@ class CommitCommand(ImportCommand): else: 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 not in ('id', 'name') + if not k.startswith('_')) + fields.update(kwargs) + return CommitCommand(**fields) + def __repr__(self): return self.to_string(include_file_contents=True) diff --git a/fastimport/tests/test_commands.py b/fastimport/tests/test_commands.py index 2d4d5d5..0da0773 100644 --- a/fastimport/tests/test_commands.py +++ b/fastimport/tests/test_commands.py @@ -197,6 +197,35 @@ 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'), + ]) + + 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_simple_copy(self): + c2 = self.c.copy() + + self.assertFalse(self.c is c2) + self.assertEqual(repr(self.c), repr(c2)) + + def test_replace_attr(self): + c2 = self.c.copy(mark='ccc') + + self.assertEqual( + repr(self.c).replace('mark :bbb', 'mark :ccc'), + repr(c2)) + + def test_invalid_attribute(self): + self.assertRaises(TypeError, self.c.copy, invalid=True) class TestFeatureDisplay(TestCase): |