Esempio n. 1
0
class BranchManagerChangeBranchTests(TestCase, ChangeBranchTestsMixin):
    """
    Tests for L{BranchManager.changeProjectBranch}.
    """
    projectName = 'Quux'

    def setUp(self):
        """
        Create a branch manager with temporary directories for all its working
        filesystem paths.
        """
        self.paths = self.mktemp()
        self.projects = self.mktemp()
        os.makedirs(self.paths)
        os.makedirs(self.projects)
        self.manager = BranchManager(self.paths, self.projects)
        self.cwd = os.getcwd()
        self.repositories = FilePath(self.mktemp())


    def tearDown(self):
        """
        Assert that the working directory has been restored to its original
        value if it was changed.
        """
        try:
            self.assertEqual(self.cwd, os.getcwd())
        finally:
            os.chdir(self.cwd)


    def createRepository(self, projectName, contents):
        """
        Create a new SVN repository with the given contents and associate it
        with given project.
        """
        path = self.repositories.child(projectName)
        path.makedirs()
        createSubversionRepository(path, contents)


    def uri(self, projectName, *branch):
        """
        Return a I{file} URI for the given branch of the given project.
        """
        return _uri(self.repositories.child(projectName), *branch)


    def checkTrunkCheckout(self, project):
        """
        Assert that a trunk checkout of the given project exists.
        """
        trunkWorkingCopy = FilePath(self.paths).child(project).child('trunk')
        self.assertTrue(
            trunkWorkingCopy.exists(),
            "%r did not exist." % (trunkWorkingCopy.path,))


    def makeRepositoryInaccessible(self, projectName):
        """
        Make the repository inaccessible so checks for the existence of
        branches can't possibly succeed.
        """
        self.repositories.child(projectName).remove()


    def modifyTrunk(self, projectName, fname, newData):
        """
        Make a change to a file in trunk.
        """
        trunkpath = FilePath(self.paths).child(projectName).child('trunk')
        f = trunkpath.child(fname).open('w')
        f.write(newData)
        f.close()


    def commitTrunk(self, projectName):
        """
        Commit the trunk working copy for the given project.
        """
        commit(
            FilePath(self.paths).child(projectName).child('trunk'),
            'Commit some changes')


    def modifyBranch(self, projectName, branchName, fname, newData):
        """
        Make a change to a file in a branch.
        """
        fObj = FilePath(self.paths).child(projectName).child(
            'branches').child(branchName).child(fname).open('w')
        fObj.write(newData)
        fObj.close()


    def commitBranch(self, projectName, branchName):
        """
        Commit a branch working for the given project.
        """
        commit(
            FilePath(self.paths).child(projectName).child(
                'branches').child(branchName),
            'Commit some changes')


    def test_mergeConflict(self):
        """
        L{BranchManager.mergeProjectBranch} performs merges
        non-interactively so that they complete even if there is a merge
        conflict.
        """
        projectName = "Quux"
        branchName = 'baz'
        fname = 'foo.txt'
        contents = {fname: 'some data'}
        self.createRepository(projectName, {"trunk": contents,
                                            "branches": {}})

        self.manager.changeProjectBranch(
            projectName, 'trunk', self.uri(projectName, 'trunk'))
        self.manager.newProjectBranch(projectName, branchName)
        self.modifyTrunk(projectName, fname, 'changed data')
        self.commitTrunk(projectName)
        self.modifyBranch(
            projectName, branchName, fname, 'differently changed data')
        self.commitBranch(projectName, branchName)

        self.manager.mergeProjectBranch(projectName)


    def test_changeCurrentBranchDeletesUnknown(self):
        """
        If L{BranchManager.changeProjectBranch} creates a new working copy, it
        doesn't contain extra unversioned files from the I{trunk} working copy.
        """
        projectName = 'Quux'
        branchName = 'foo'

        self.createRepository(
            projectName, {'trunk': {},
                          'branches':
                              {branchName: {}}})

        # Get a trunk checkout
        self.manager.changeProjectBranch(
            projectName, 'trunk', self.uri(projectName, 'trunk'))

        # Here is some unversioned junk in the trunk working copy
        self.modifyTrunk(projectName, "junk", "garbage")

        self.manager.changeProjectBranch(projectName, branchName)

        junk = FilePath(self.paths).descendant([
                projectName, "branches", branchName, "junk"])
        self.assertFalse(junk.exists())
Esempio n. 2
0
class BranchManagerChangeBranchTests(TestCase, ChangeBranchTestsMixin):
    """
    Tests for L{BranchManager.changeProjectBranch}.
    """
    projectName = 'Quux'

    def setUp(self):
        """
        Create a branch manager with temporary directories for all its working
        filesystem paths.
        """
        self.paths = self.mktemp()
        self.projects = self.mktemp()
        os.makedirs(self.paths)
        os.makedirs(self.projects)
        self.manager = BranchManager(self.paths, self.projects)
        self.cwd = os.getcwd()
        self.repositories = FilePath(self.mktemp())

    def tearDown(self):
        """
        Assert that the working directory has been restored to its original
        value if it was changed.
        """
        try:
            self.assertEqual(self.cwd, os.getcwd())
        finally:
            os.chdir(self.cwd)

    def createRepository(self, projectName, contents):
        """
        Create a new SVN repository with the given contents and associate it
        with given project.
        """
        path = self.repositories.child(projectName)
        path.makedirs()
        createSubversionRepository(path, contents)

    def uri(self, projectName, *branch):
        """
        Return a I{file} URI for the given branch of the given project.
        """
        return _uri(self.repositories.child(projectName), *branch)

    def checkTrunkCheckout(self, project):
        """
        Assert that a trunk checkout of the given project exists.
        """
        trunkWorkingCopy = FilePath(self.paths).child(project).child('trunk')
        self.assertTrue(trunkWorkingCopy.exists(),
                        "%r did not exist." % (trunkWorkingCopy.path, ))

    def makeRepositoryInaccessible(self, projectName):
        """
        Make the repository inaccessible so checks for the existence of
        branches can't possibly succeed.
        """
        self.repositories.child(projectName).remove()

    def modifyTrunk(self, projectName, fname, newData):
        """
        Make a change to a file in trunk.
        """
        trunkpath = FilePath(self.paths).child(projectName).child('trunk')
        f = trunkpath.child(fname).open('w')
        f.write(newData)
        f.close()

    def commitTrunk(self, projectName):
        """
        Commit the trunk working copy for the given project.
        """
        commit(
            FilePath(self.paths).child(projectName).child('trunk'),
            'Commit some changes')

    def modifyBranch(self, projectName, branchName, fname, newData):
        """
        Make a change to a file in a branch.
        """
        fObj = FilePath(self.paths).child(projectName).child('branches').child(
            branchName).child(fname).open('w')
        fObj.write(newData)
        fObj.close()

    def commitBranch(self, projectName, branchName):
        """
        Commit a branch working for the given project.
        """
        commit(
            FilePath(self.paths).child(projectName).child('branches').child(
                branchName), 'Commit some changes')

    def test_mergeConflict(self):
        """
        L{BranchManager.mergeProjectBranch} performs merges
        non-interactively so that they complete even if there is a merge
        conflict.
        """
        projectName = "Quux"
        branchName = 'baz'
        fname = 'foo.txt'
        contents = {fname: 'some data'}
        self.createRepository(projectName, {"trunk": contents, "branches": {}})

        self.manager.changeProjectBranch(projectName, 'trunk',
                                         self.uri(projectName, 'trunk'))
        self.manager.newProjectBranch(projectName, branchName)
        self.modifyTrunk(projectName, fname, 'changed data')
        self.commitTrunk(projectName)
        self.modifyBranch(projectName, branchName, fname,
                          'differently changed data')
        self.commitBranch(projectName, branchName)

        self.manager.mergeProjectBranch(projectName)