Move merge tests to their own file
The method is in Repository, but the merge functionality is separate. We will introduce more tests in this area later.
This commit is contained in:
103
test/test_merge.py
Normal file
103
test/test_merge.py
Normal file
@@ -0,0 +1,103 @@
|
||||
# -*- coding: UTF-8 -*-
|
||||
#
|
||||
# Copyright 2010-2014 The pygit2 contributors
|
||||
#
|
||||
# This file is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License, version 2,
|
||||
# as published by the Free Software Foundation.
|
||||
#
|
||||
# In addition to the permissions in the GNU General Public License,
|
||||
# the authors give you unlimited permission to link the compiled
|
||||
# version of this file into combinations with other programs,
|
||||
# and to distribute those combinations without any restriction
|
||||
# coming from the use of this file. (The General Public License
|
||||
# restrictions do apply in other respects; for example, they cover
|
||||
# modification of the file, and distribution when not linked into
|
||||
# a combined executable.)
|
||||
#
|
||||
# This file is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; see the file COPYING. If not, write to
|
||||
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
||||
# Boston, MA 02110-1301, USA.
|
||||
|
||||
"""Tests for merging and information about it."""
|
||||
|
||||
# Import from the future
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import unittest
|
||||
import os
|
||||
|
||||
from pygit2 import GIT_MERGE_ANALYSIS_NONE, GIT_MERGE_ANALYSIS_NORMAL, GIT_MERGE_ANALYSIS_UP_TO_DATE
|
||||
from pygit2 import GIT_MERGE_ANALYSIS_FASTFORWARD, GIT_MERGE_ANALYSIS_UNBORN
|
||||
import pygit2
|
||||
|
||||
from . import utils
|
||||
|
||||
class MergeTestBasic(utils.RepoTestCaseForMerging):
|
||||
|
||||
def test_merge_none(self):
|
||||
self.assertRaises(TypeError, self.repo.merge, None)
|
||||
|
||||
def test_merge_analysis_uptodate(self):
|
||||
branch_head_hex = '5ebeeebb320790caf276b9fc8b24546d63316533'
|
||||
branch_id = self.repo.get(branch_head_hex).id
|
||||
analysis, preference = self.repo.merge_analysis(branch_id)
|
||||
|
||||
self.assertTrue(analysis & GIT_MERGE_ANALYSIS_UP_TO_DATE)
|
||||
self.assertFalse(analysis & GIT_MERGE_ANALYSIS_FASTFORWARD)
|
||||
self.assertEqual({}, self.repo.status())
|
||||
|
||||
def test_merge_analysis_fastforward(self):
|
||||
branch_head_hex = 'e97b4cfd5db0fb4ebabf4f203979ca4e5d1c7c87'
|
||||
branch_id = self.repo.get(branch_head_hex).id
|
||||
analysis, preference = self.repo.merge_analysis(branch_id)
|
||||
self.assertFalse(analysis & GIT_MERGE_ANALYSIS_UP_TO_DATE)
|
||||
self.assertTrue(analysis & GIT_MERGE_ANALYSIS_FASTFORWARD)
|
||||
self.assertEqual({}, self.repo.status())
|
||||
|
||||
def test_merge_no_fastforward_no_conflicts(self):
|
||||
branch_head_hex = '03490f16b15a09913edb3a067a3dc67fbb8d41f1'
|
||||
branch_id = self.repo.get(branch_head_hex).id
|
||||
analysis, preference = self.repo.merge_analysis(branch_id)
|
||||
self.assertFalse(analysis & GIT_MERGE_ANALYSIS_UP_TO_DATE)
|
||||
self.assertFalse(analysis & GIT_MERGE_ANALYSIS_FASTFORWARD)
|
||||
# Asking twice to assure the reference counting is correct
|
||||
self.assertEqual({}, self.repo.status())
|
||||
self.assertEqual({}, self.repo.status())
|
||||
|
||||
def test_merge_no_fastforward_conflicts(self):
|
||||
branch_head_hex = '1b2bae55ac95a4be3f8983b86cd579226d0eb247'
|
||||
branch_id = self.repo.get(branch_head_hex).id
|
||||
|
||||
analysis, preference = self.repo.merge_analysis(branch_id)
|
||||
self.assertFalse(analysis & GIT_MERGE_ANALYSIS_UP_TO_DATE)
|
||||
self.assertFalse(analysis & GIT_MERGE_ANALYSIS_FASTFORWARD)
|
||||
|
||||
self.repo.merge(branch_id)
|
||||
status = pygit2.GIT_STATUS_WT_NEW | pygit2.GIT_STATUS_INDEX_DELETED
|
||||
# Asking twice to assure the reference counting is correct
|
||||
self.assertEqual({'.gitignore': status}, self.repo.status())
|
||||
self.assertEqual({'.gitignore': status}, self.repo.status())
|
||||
# Checking the index works as expected
|
||||
self.repo.index.add('.gitignore')
|
||||
self.repo.index.write()
|
||||
self.assertEqual({'.gitignore': pygit2.GIT_STATUS_INDEX_MODIFIED}, self.repo.status())
|
||||
|
||||
def test_merge_invalid_hex(self):
|
||||
branch_head_hex = '12345678'
|
||||
self.assertRaises(KeyError, self.repo.merge, branch_head_hex)
|
||||
|
||||
def test_merge_already_something_in_index(self):
|
||||
branch_head_hex = '03490f16b15a09913edb3a067a3dc67fbb8d41f1'
|
||||
branch_oid = self.repo.get(branch_head_hex).id
|
||||
with open(os.path.join(self.repo.workdir, 'inindex.txt'), 'w') as f:
|
||||
f.write('new content')
|
||||
self.repo.index.add('inindex.txt')
|
||||
self.assertRaises(pygit2.GitError, self.repo.merge, branch_oid)
|
@@ -40,8 +40,6 @@ from os.path import join, realpath
|
||||
|
||||
# Import from pygit2
|
||||
from pygit2 import GIT_OBJ_ANY, GIT_OBJ_BLOB, GIT_OBJ_COMMIT
|
||||
from pygit2 import GIT_MERGE_ANALYSIS_NONE, GIT_MERGE_ANALYSIS_NORMAL, GIT_MERGE_ANALYSIS_UP_TO_DATE
|
||||
from pygit2 import GIT_MERGE_ANALYSIS_FASTFORWARD, GIT_MERGE_ANALYSIS_UNBORN
|
||||
from pygit2 import init_repository, clone_repository, clone_into, discover_repository
|
||||
from pygit2 import Oid, Reference, hashfile
|
||||
import pygit2
|
||||
@@ -318,69 +316,6 @@ class RepositoryTest_II(utils.RepoTestCase):
|
||||
self.assertTrue("hola mundo\n" in diff.patch)
|
||||
self.assertTrue("bonjour le monde\n" in diff.patch)
|
||||
|
||||
|
||||
class RepositoryTest_III(utils.RepoTestCaseForMerging):
|
||||
|
||||
def test_merge_none(self):
|
||||
self.assertRaises(TypeError, self.repo.merge, None)
|
||||
|
||||
def test_merge_analysis_uptodate(self):
|
||||
branch_head_hex = '5ebeeebb320790caf276b9fc8b24546d63316533'
|
||||
branch_id = self.repo.get(branch_head_hex).id
|
||||
analysis, preference = self.repo.merge_analysis(branch_id)
|
||||
|
||||
self.assertTrue(analysis & GIT_MERGE_ANALYSIS_UP_TO_DATE)
|
||||
self.assertFalse(analysis & GIT_MERGE_ANALYSIS_FASTFORWARD)
|
||||
self.assertEqual({}, self.repo.status())
|
||||
|
||||
def test_merge_analysis_fastforward(self):
|
||||
branch_head_hex = 'e97b4cfd5db0fb4ebabf4f203979ca4e5d1c7c87'
|
||||
branch_id = self.repo.get(branch_head_hex).id
|
||||
analysis, preference = self.repo.merge_analysis(branch_id)
|
||||
self.assertFalse(analysis & GIT_MERGE_ANALYSIS_UP_TO_DATE)
|
||||
self.assertTrue(analysis & GIT_MERGE_ANALYSIS_FASTFORWARD)
|
||||
self.assertEqual({}, self.repo.status())
|
||||
|
||||
def test_merge_no_fastforward_no_conflicts(self):
|
||||
branch_head_hex = '03490f16b15a09913edb3a067a3dc67fbb8d41f1'
|
||||
branch_id = self.repo.get(branch_head_hex).id
|
||||
analysis, preference = self.repo.merge_analysis(branch_id)
|
||||
self.assertFalse(analysis & GIT_MERGE_ANALYSIS_UP_TO_DATE)
|
||||
self.assertFalse(analysis & GIT_MERGE_ANALYSIS_FASTFORWARD)
|
||||
# Asking twice to assure the reference counting is correct
|
||||
self.assertEqual({}, self.repo.status())
|
||||
self.assertEqual({}, self.repo.status())
|
||||
|
||||
def test_merge_no_fastforward_conflicts(self):
|
||||
branch_head_hex = '1b2bae55ac95a4be3f8983b86cd579226d0eb247'
|
||||
branch_id = self.repo.get(branch_head_hex).id
|
||||
|
||||
analysis, preference = self.repo.merge_analysis(branch_id)
|
||||
self.assertFalse(analysis & GIT_MERGE_ANALYSIS_UP_TO_DATE)
|
||||
self.assertFalse(analysis & GIT_MERGE_ANALYSIS_FASTFORWARD)
|
||||
|
||||
self.repo.merge(branch_id)
|
||||
status = pygit2.GIT_STATUS_WT_NEW | pygit2.GIT_STATUS_INDEX_DELETED
|
||||
# Asking twice to assure the reference counting is correct
|
||||
self.assertEqual({'.gitignore': status}, self.repo.status())
|
||||
self.assertEqual({'.gitignore': status}, self.repo.status())
|
||||
# Checking the index works as expected
|
||||
self.repo.index.add('.gitignore')
|
||||
self.repo.index.write()
|
||||
self.assertEqual({'.gitignore': pygit2.GIT_STATUS_INDEX_MODIFIED}, self.repo.status())
|
||||
|
||||
def test_merge_invalid_hex(self):
|
||||
branch_head_hex = '12345678'
|
||||
self.assertRaises(KeyError, self.repo.merge, branch_head_hex)
|
||||
|
||||
def test_merge_already_something_in_index(self):
|
||||
branch_head_hex = '03490f16b15a09913edb3a067a3dc67fbb8d41f1'
|
||||
branch_oid = self.repo.get(branch_head_hex).id
|
||||
with open(os.path.join(self.repo.workdir, 'inindex.txt'), 'w') as f:
|
||||
f.write('new content')
|
||||
self.repo.index.add('inindex.txt')
|
||||
self.assertRaises(pygit2.GitError, self.repo.merge, branch_oid)
|
||||
|
||||
class RepositorySignatureTest(utils.RepoTestCase):
|
||||
|
||||
def test_default_signature(self):
|
||||
|
Reference in New Issue
Block a user