view tests/test_pull.py @ 313:942f198b8ff5

hg_delta_editor: detect new branches issued from non-branch directories This fix solves the following case: let's /dumb/layout/project be an existing project. To normalize the trunk/branches/tags layout, people may do: $ mkdir /project $ mv /dumb/layout/project /project/project # Oups, should have been trunk! $ mv /project/project /project/trunk trunk creation was ignore because: - update_branch_map() sees it come from a non-branch copy source and ignores it (case #3). - since it is not in self.branches, add_directory() ignores the non-existing path. Then trunk is left uninitialized. To solve this, we allow update_branch_map() to detect branches copied from non-canonical locations.
author Patrick Mezard <pmezard@gmail.com>
date Sun, 03 May 2009 21:42:42 -0500
parents 521d9c1bb11d
children 75f082b5897e
line wrap: on
line source

import test_util

import os.path
import subprocess
from mercurial import ui

import wrappers


class TestPull(test_util.TestBase):
    def setUp(self):
        super(TestPull, self).setUp()
        self.svn_wc = None

    def _load_fixture_and_fetch(self, fixture_name):
        return test_util.load_fixture_and_fetch(fixture_name, self.repo_path,
                                                self.wc_path, stupid=False,
                                                noupdate=False)

    def _add_svn_rev(self, changes):
        # changes is a dict of filename -> contents
        if self.svn_wc is None:
            self.svn_wc = os.path.join(self.tmpdir, 'testsvn_wc')
            subprocess.call([
                'svn', 'co', '-q', test_util.fileurl(self.repo_path), 
                self.svn_wc
            ])

        for filename, contents in changes.iteritems():
            # filenames are / separated
            filename = filename.replace('/', os.path.sep)
            filename = os.path.join(self.svn_wc, filename)
            open(filename, 'w').write(contents)
            subprocess.call(['svn', 'add', '-q', filename]) # may be redundant
        subprocess.call([
            'svn', 'commit', '-q', self.svn_wc, '-m', 'test changes'])

    def test_nochanges(self):
        repo = self._load_fixture_and_fetch('single_rev.svndump')
        state = repo.parents()
        wrappers.pull(None, ui.ui(), repo)
        self.assertEqual(state, repo.parents())

    def test_onerevision_noupdate(self):
        repo = self._load_fixture_and_fetch('single_rev.svndump')
        state = repo.parents()
        self._add_svn_rev({'trunk/alpha': 'Changed'})
        wrappers.pull(None, ui.ui(), repo)
        self.assertEqual(state, repo.parents())
        self.assertTrue('tip' not in repo[None].tags())
    
    def test_onerevision_doupdate(self):
        repo = self._load_fixture_and_fetch('single_rev.svndump')
        state = repo.parents()
        self._add_svn_rev({'trunk/alpha': 'Changed'})
        wrappers.pull(None, ui.ui(), repo, update=True)
        self.failIfEqual(state, repo.parents())
        self.assertTrue('tip' in repo[None].tags())

    def test_onerevision_divergent(self):
        repo = self._load_fixture_and_fetch('single_rev.svndump')
        self.commitchanges((('alpha', 'alpha', 'Changed another way'),))
        state = repo.parents()
        self._add_svn_rev({'trunk/alpha': 'Changed one way'})
        wrappers.pull(None, ui.ui(), repo, update=True)
        self.assertEqual(state, repo.parents())
        self.assertTrue('tip' not in repo[None].tags())
        self.assertEqual(len(repo.heads()), 2)

def suite():
    import unittest, sys
    return unittest.findTestCases(sys.modules[__name__])