示例#1
0
    def test_local_merge(self, vcsbackend_hg):
        target_repo = vcsbackend_hg.create_repo(number_of_commits=1)
        source_repo = vcsbackend_hg.clone_repo(target_repo)
        vcsbackend_hg.add_file(target_repo, 'README_MERGE1', 'Version 1')
        target_repo = MercurialRepository(target_repo.path)
        target_rev = target_repo.branches['default']
        target_ref = Reference(type='branch',
                               name='default',
                               commit_id=target_rev)
        vcsbackend_hg.add_file(source_repo, 'README_MERGE2', 'Version 2')
        source_repo = MercurialRepository(source_repo.path)
        source_rev = source_repo.branches['default']
        source_ref = Reference(type='branch',
                               name='default',
                               commit_id=source_rev)

        target_repo._local_pull(source_repo.path, source_ref)

        merge_message = 'Merge message\n\nDescription:...'
        user_name = 'Albert Einstein'
        user_email = '*****@*****.**'
        merge_commit_id, needs_push = target_repo._local_merge(
            target_ref, merge_message, user_name, user_email, source_ref)
        assert needs_push

        target_repo = MercurialRepository(target_repo.path)
        assert target_repo.commit_ids[-3] == target_rev
        assert target_repo.commit_ids[-2] == source_rev
        last_commit = target_repo.get_commit(merge_commit_id)
        assert last_commit.message.strip() == merge_message
        assert last_commit.author == '%s <%s>' % (user_name, user_email)

        assert not os.path.exists(
            os.path.join(target_repo.path, '.hg', 'merge', 'state'))
示例#2
0
    def test_local_merge_raises_exception_on_conflict(self, vcsbackend_hg):
        target_repo = vcsbackend_hg.create_repo(number_of_commits=1)
        source_repo = vcsbackend_hg.clone_repo(target_repo)
        vcsbackend_hg.add_file(target_repo, 'README_MERGE', 'Version 1')
        target_repo = MercurialRepository(target_repo.path)
        target_rev = target_repo.branches['default']
        target_ref = Reference(type='branch',
                               name='default',
                               commit_id=target_rev)
        vcsbackend_hg.add_file(source_repo, 'README_MERGE', 'Version 2')
        source_repo = MercurialRepository(source_repo.path)
        source_rev = source_repo.branches['default']
        source_ref = Reference(type='branch',
                               name='default',
                               commit_id=source_rev)

        target_repo._local_pull(source_repo.path, source_ref)
        with pytest.raises(RepositoryError):
            target_repo._local_merge(target_ref, 'merge_message', 'user name',
                                     '*****@*****.**', source_ref)

        # Check we are not left in an intermediate merge state
        assert not os.path.exists(
            os.path.join(target_repo.path, '.hg', 'merge', 'state'))