def test_file_move(self): from fastimport import commands self.simple_commit() commit = self.make_file_commit([commands.FileRenameCommand("path", "new_path")]) self.assertEquals([ ('new_path', 0100644, '6320cd248dd8aeaab759d5871f8781b5c0505172'), ], self.repo[commit.tree].items())
def iter_file_commands(self): """Iterator returning FileCommand objects. If an invalid file command is found, the line is silently pushed back and iteration ends. """ while True: line = self.next_line() if line is None: break elif len(line) == 0 or line.startswith(b'#'): continue # Search for file commands in order of likelihood elif line.startswith(b'M '): yield self._parse_file_modify(line[2:]) elif line.startswith(b'D '): path = self._path(line[2:]) yield commands.FileDeleteCommand(path) elif line.startswith(b'R '): old, new = self._path_pair(line[2:]) yield commands.FileRenameCommand(old, new) elif line.startswith(b'C '): src, dest = self._path_pair(line[2:]) yield commands.FileCopyCommand(src, dest) elif line.startswith(b'deleteall'): yield commands.FileDeleteAllCommand() else: self.push_line(line) break
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_filerename_quoted(self): # Check the first path is quoted if it contains spaces c = commands.FileRenameCommand(b'foo/b a r', b'foo/b a z') self.assertEqual(b'R "foo/b a r" foo/b a z', bytes(c))
def test_filerename(self): c = commands.FileRenameCommand(b'foo/bar', b'foo/baz') self.assertEqual(b'R foo/bar foo/baz', bytes(c))