def simple_commit(self): from fastimport import commands cmd = commands.BlobCommand(b"23", b"data") self.processor.blob_handler(cmd) cmd = commands.CommitCommand(b"refs/heads/foo", b"mrkr", (b"Jelmer", b"*****@*****.**", 432432432.0, 3600), (b"Jelmer", b"*****@*****.**", 432432432.0, 3600), b"FOO", None, [], [commands.FileModifyCommand(b"path", 0o100644, b":23", None)]) self.processor.commit_handler(cmd) commit = self.repo[self.processor.last_commit] return commit
def setUp(self): super(TestCommitCopy, self).setUp() file_cmds = iter([ commands.FileDeleteCommand(b'readme.txt'), commands.FileModifyCommand(b'NEWS', 0o100644, None, b'blah blah blah'), ]) committer = (b'Joe Wong', b'*****@*****.**', 1234567890, -6 * 3600) self.c = commands.CommitCommand(b'refs/heads/master', b'bbb', None, committer, b'release v1.0', b':aaa', None, file_cmds)
def _iter_files(self, base_tree, new_tree): for (old_path, new_path), (old_mode, new_mode), (old_hexsha, new_hexsha) in \ self.store.tree_changes(base_tree, new_tree): if new_path is None: yield commands.FileDeleteCommand(old_path) continue if not stat.S_ISDIR(new_mode): blob = self.store[new_hexsha] marker = self.emit_blob(blob) if old_path != new_path and old_path is not None: yield commands.FileRenameCommand(old_path, new_path) if old_mode != new_mode or old_hexsha != new_hexsha: yield commands.FileModifyCommand(new_path, new_mode, marker, None)
def test_file_add(self): from fastimport import commands cmd = commands.BlobCommand(b"23", b"data") self.processor.blob_handler(cmd) cmd = commands.CommitCommand(b"refs/heads/foo", b"mrkr", (b"Jelmer", b"*****@*****.**", 432432432.0, 3600), (b"Jelmer", b"*****@*****.**", 432432432.0, 3600), b"FOO", None, [], [commands.FileModifyCommand(b"path", 0o100644, b":23", None)]) self.processor.commit_handler(cmd) commit = self.repo[self.processor.last_commit] self.assertEqual([ (b'path', 0o100644, b'6320cd248dd8aeaab759d5871f8781b5c0505172')], self.repo[commit.tree].items())
def _parse_file_modify(self, info): """Parse a filemodify command within a commit. :param info: a string in the format "mode dataref path" (where dataref might be the hard-coded literal 'inline'). """ params = info.split(b' ', 2) path = self._path(params[2]) mode = self._mode(params[0]) if params[1] == b'inline': dataref = None data = self._get_data(b'filemodify') else: dataref = params[1] data = None return commands.FileModifyCommand(path, mode, dataref, data)
def test_commit_with_filecommands(self): file_cmds = iter([ commands.FileDeleteCommand(b'readme.txt'), commands.FileModifyCommand(b'NEWS', 0o100644, None, b'blah blah blah'), ]) # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc) committer = (b'Joe Wong', b'*****@*****.**', 1234567890, -6 * 3600) c = commands.CommitCommand(b'refs/heads/master', b'bbb', None, committer, b'release v1.0', b':aaa', None, file_cmds) self.assertEqual( b"commit refs/heads/master\n" b"mark :bbb\n" b"committer Joe Wong <*****@*****.**> 1234567890 -0600\n" b"data 12\n" b"release v1.0\n" b"from :aaa\n" b"D readme.txt\n" b"M 644 inline NEWS\n" b"data 14\n" b"blah blah blah", bytes(c))
def test_notecommit(self): committer = (b'Ed Mund', b'*****@*****.**', 1234565432, 0) commits = [ commands.CommitCommand(ref=b'refs/heads/master', mark=b'1', author=committer, committer=committer, message=b'test\n', from_=None, merges=[], file_iter=[ commands.FileModifyCommand( b'bar', 0o100644, None, b'') ]), commands.CommitCommand( ref=b'refs/notes/commits', mark=None, author=None, committer=committer, message=b"Notes added by 'git notes add'\n", from_=None, merges=[], file_iter=[commands.NoteModifyCommand(b'1', b'Test note\n')]), commands.CommitCommand( ref=b'refs/notes/test', mark=None, author=None, committer=committer, message=b"Notes added by 'git notes add'\n", from_=None, merges=[], file_iter=[commands.NoteModifyCommand(b'1', b'Test test\n')]) ] self.assertEqual( b"""commit refs/heads/master mark :1 author Ed Mund <*****@*****.**> 1234565432 +0000 committer Ed Mund <*****@*****.**> 1234565432 +0000 data 5 test M 644 inline bar data 0 commit refs/notes/commits committer Ed Mund <*****@*****.**> 1234565432 +0000 data 31 Notes added by 'git notes add' N inline :1 data 10 Test note commit refs/notes/test committer Ed Mund <*****@*****.**> 1234565432 +0000 data 31 Notes added by 'git notes add' N inline :1 data 10 Test test """, b''.join([bytes(s) for s in commits]))
def test_filemodify_treeref(self): c = commands.FileModifyCommand(b'tree-info', 0o160000, b'revision-id-info', None) self.assertEqual(b'M 160000 revision-id-info tree-info', bytes(c))
def test_filemodify_symlink(self): c = commands.FileModifyCommand(b'foo/bar', 0o120000, None, b'baz') self.assertEqual(b'M 120000 inline foo/bar\ndata 3\nbaz', bytes(c))
def test_filemodify_file_internal(self): c = commands.FileModifyCommand(b'foo/bar', 0o100644, None, b'hello world') self.assertEqual(b'M 644 inline foo/bar\ndata 11\nhello world', bytes(c))
def test_filemodify_file_executable(self): c = commands.FileModifyCommand(b'foo/bar', 0o100755, b':23', None) self.assertEqual(b'M 755 :23 foo/bar', bytes(c))
def test_filemodify_file(self): c = commands.FileModifyCommand(b'foo/bar', 0o100644, b':23', None) self.assertEqual(b'M 644 :23 foo/bar', bytes(c))