Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
 def test_file_deleteall(self):
     from fastimport import commands
     self.simple_commit()
     commit = self.make_file_commit([commands.FileDeleteAllCommand()])
     self.assertEqual([], self.repo[commit.tree].items())
Ejemplo n.º 3
0
 def test_filedeleteall(self):
     c = commands.FileDeleteAllCommand()
     self.assertEqual(b'deleteall', bytes(c))