示例#1
0
class Test(unittest.TestCase):

    def setUp(self):
        """Clone the initial CVS repository into a temporary directory and
        change the working directory to the new work tree.
        """
        self.oldcwd = getcwd()
        self.tempdir = tempfile.mkdtemp()
        self.cvsroot = join(self.tempdir, 'cvs')
        self.worktree = join(self.tempdir, 'git')

        # Clone the initial CVS repository.
        TarFile('cvsroot').extract(self.cvsroot)
        TarFile('import').extract(self.cvsroot)
        chdir(self.tempdir)
        self.assertEquals(Clone().eval('--quiet', '--no-skip-latest',
            join(self.cvsroot, 'src'), self.worktree), 0)

        # Enter the work tree and make sure the clone was successful before
        # running the actual test case.
        chdir(self.worktree)
        self.assertEquals(Verify().eval(), 0)

        # Verify the intial Git state after cloning from "cvs import".
        self.git = Git(self.worktree)
        self.assertEquals(
            ['21d3c522acefc5d240848876968504d8ea85347f'],
            split(self.git.rev_list('HEAD')))

    def tearDown(self):
        """Return to the original working directory and remove the whole
        temporary directory.
        """
        # Ensure that the working copy is the same as cloning from CVS at
        # the end of each test fixture.
        self.assertEquals(Verify().eval(), 0)

        # Restore the original working directory.
        chdir(self.oldcwd)
        if isdir(self.tempdir):
            shutil.rmtree(self.tempdir)

    def test_initial_clone(self):
        """Pull without changes in CVS does nothing.

        Running "git cvs pull" right after an initial "git cvs clone"
        should not change the working copy in any way, even if an RCS
        file has an updated timestamp and is therefore parsed again.
        """
        touch_existing(join(self.cvsroot, 'src', 'file_a,v'))
        old_content = directory_listing(self.worktree)
        with redirect_stdout() as stdout:
            self.assertEquals(pull().eval('--no-skip-latest'), 0)
            self.assertEquals(stdout.getvalue(),
                re.sub('^\s*', '', """\
                Collecting RCS files: 1
                Parsing RCS files: done. (1/1)
                Processing changes: done. (0/0)
                """, 0, re.MULTILINE))
        new_content = directory_listing(self.worktree)
        self.assertEquals(old_content, new_content)

    def test_pull_new_file(self):
        """Pull a change that adds a new file.
        """
        TarFile('add-file_b').extract(self.cvsroot)
        self.assertEquals(isfile('file_a'), True)
        self.assertEquals(isfile('file_b'), False)
        with redirect_stdout() as stdout:
            self.assertEquals(pull().eval('--no-skip-latest'), 0)
            self.assertEquals(
                re.sub('^\s*', '', """\
                Collecting RCS files: 2
                Parsing RCS files: done. (1/1)
                Processing changes: done. (1/1)
                Importing changesets: done. (1/1)
                """, 0, re.MULTILINE),
                stdout.getvalue())
        self.assertEquals(isfile('file_b'), True)
        self.assertEquals(
            ['675ccc10b5cdca1ead0eec6020a16e3d51b8e548',
             '21d3c522acefc5d240848876968504d8ea85347f'],
            split(self.git.rev_list('HEAD')))

    def test_incomplete_commit(self):
        """Incomplete change sets are ignored by default.
        """
        TarFile('add-file_b').extract(self.cvsroot)
        TarFile('split-commit-part1').extract(self.cvsroot)
        with redirect_stdout() as stdout:
            self.assertEquals(pull().eval(), 0)
            self.assertEquals(
                ['Collecting RCS files: 2',
                 'Parsing RCS files: done. (2/2)',
                 'Processing changes: done. (3/3)',
                 'Retained changesets: 1',
                 'Importing changesets:  50% (1/2)',
                 'Importing changesets: done. (2/2)'],
                splitlines(stdout.getvalue()))
        self.assertEquals(
            ['24231f1cd29a5e1caaf9c0167283b8aa5955ea7f',
             '8d60be7401bafc50256ec624d1aa2ef3b63a2a41',
             '21d3c522acefc5d240848876968504d8ea85347f'],
            split(self.git.rev_list('HEAD')))