def test_merge_isuptodate(self): gitrepo = Repository(self.cloned_from_repo) gitrepo.update('master') uptodate_hash = '52109e71fd7f16cb366acfcbb140d6d7f2fc50c9' cs = gitrepo[uptodate_hash] should_be_none = gitrepo.merge(other_rev=cs) self.assertIsNone(should_be_none)
def test_merge_isuptodate(self): gitrepo = Repository(self.cloned_from_repo) gitrepo.update('master') uptodate_hash = '52109e71fd7f16cb366acfcbb140d6d7f2fc50c9' cs = gitrepo[uptodate_hash] should_be_none = gitrepo.merge(other_rev=cs) self.assertIsNone(should_be_none)
def test_is_merge(self): git = GitCmd(self.cloned_from_repo) headnewbranch = git('show-ref', '-s', 'refs/heads/newbranch') gitrepo = Repository(self.cloned_from_repo) self.assertFalse(gitrepo.is_merge(git('rev-parse', 'HEAD'))) # Do a merge gitrepo.update('master') merge_rev = gitrepo.merge(other_rev=gitrepo[headnewbranch]) self.assertTrue(gitrepo.is_merge(merge_rev.hash))
def test_merge_no_conflicts(self): git = GitCmd(self.cloned_from_repo) headnewbranch = git('rev-parse', 'refs/heads/newbranch') gitrepo = Repository(self.cloned_from_repo) # Checkout to master gitrepo.update('master') cs = gitrepo.merge(other_rev=gitrepo[headnewbranch]) self.assertEquals(len(git('log', '-1', pretty='%P').split()), 2) self.assertEquals(git('rev-parse', 'HEAD'), cs.hash)
def test_is_merge(self): git = GitCmd(self.cloned_from_repo) headnewbranch = git('show-ref', '-s', 'refs/heads/newbranch') gitrepo = Repository(self.cloned_from_repo) self.assertFalse(gitrepo.is_merge(git('rev-parse', 'HEAD'))) # Do a merge gitrepo.update('master') merge_rev = gitrepo.merge(other_rev=gitrepo[headnewbranch]) self.assertTrue(gitrepo.is_merge(merge_rev.hash))
def test_is_merge(self): repo = pygit2.Repository(self.cloned_from_repo) reference = repo.lookup_reference('refs/remotes/origin/newbranch') headnewbranch = reference.get_object().hex gitrepo = Repository(self.cloned_from_repo) self.assertFalse(gitrepo.is_merge(repo.head.get_object().hex)) # Do a merge gitrepo.update('master') merge_rev = gitrepo.merge(other_rev=gitrepo[headnewbranch]) self.assertTrue(gitrepo.is_merge(merge_rev.hash))
def test_merge_with_conflict(self): gitrepo = Repository(self.cloned_from_repo) # Checkout gitrepo.update('newbranch') file_to_conflict_name = 'test1.txt' file_to_conflict = os.path.join(self.cloned_from_repo, file_to_conflict_name) with open(file_to_conflict, "w") as file: file_content = "Absurd content" file.write(file_content) gitrepo.add(file_to_conflict_name) conflict_cs = gitrepo.commit("Provoking conflict") gitrepo.update('master') try: gitrepo.merge(other_rev=conflict_cs) self.fail() except MergeConflictError as exp: self.assertTrue('Conflicts found: merging test1.txt failed' in exp)
def test_merge_no_conflicts(self): repo = pygit2.Repository(self.cloned_from_repo) headnewbranch = repo.lookup_reference( 'refs/remotes/origin/newbranch').get_object().hex gitrepo = Repository(self.cloned_from_repo) # Checkout to master gitrepo.update('master') cs = gitrepo.merge(other_rev=gitrepo[headnewbranch]) self.assertEquals(len(repo.head.get_object().parents), 2) self.assertEquals(repo.head.get_object().hex, cs.hash)
def test_merge_no_conflicts(self): git = GitCmd(self.cloned_from_repo) headnewbranch = git('rev-parse', 'refs/heads/newbranch') gitrepo = Repository(self.cloned_from_repo) # Checkout to master gitrepo.update('master') cs = gitrepo.merge(other_rev=gitrepo[headnewbranch]) self.assertEquals(len(git('log', '-1', pretty='%P').split()), 2) self.assertEquals(git('rev-parse', 'HEAD'), cs.hash)
def test_merge_with_conflict(self): gitrepo = Repository(self.cloned_from_repo) # Checkout gitrepo.update('newbranch') file_to_conflict_name = 'test1.txt' file_to_conflict = os.path.join(self.cloned_from_repo, file_to_conflict_name) with open(file_to_conflict, "w") as file: file_content = "Absurd content" file.write(file_content) gitrepo.add(file_to_conflict_name) conflict_cs = gitrepo.commit("Provoking conflict") gitrepo.update('master') try: gitrepo.merge(other_rev=conflict_cs) self.fail('Merge with conflict should have failed') except MergeConflictError as exp: print exp self.assertTrue('Conflicts found: merging test1.txt failed' in exp)
def test_merge_fastforward_no_ff(self): git = GitCmd(self.cloned_from_repo) gitrepo = Repository(self.cloned_from_repo) gitrepo.update('master') gitrepo.branch('ff-branch') ff_file_name = 'ff-file.txt' ff_file = os.path.join(self.cloned_from_repo, ff_file_name) with open(ff_file, "w") as file: file_content = "Absurd content" file.write(file_content) gitrepo.add(ff_file_name) ff_head = gitrepo.commit(message="commit ff file") gitrepo.update('master') cs = gitrepo.merge(other_rev=ff_head, other_branch_name='test') self.assertEquals(len(git('log', '-1', pretty='%P').split()), 2) self.assertEquals(git('rev-parse', 'HEAD'), cs.hash) # We want a commit in fastforward merges, hashes must be different self.assertNotEquals(ff_head.hash, cs.hash) self.assertTrue(os.path.isfile(ff_file))
def test_merge_fastforward_no_ff(self): repo = pygit2.Repository(self.cloned_from_repo) gitrepo = Repository(self.cloned_from_repo) gitrepo.update('master') gitrepo.branch('ff-branch') ff_file_name = 'ff-file.txt' ff_file = os.path.join(self.cloned_from_repo, ff_file_name) with open(ff_file, "w") as file: file_content = "Absurd content" file.write(file_content) gitrepo.add(ff_file_name) ff_head = gitrepo.commit(message="commit ff file") gitrepo.update('master') cs = gitrepo.merge(other_rev=ff_head, other_branch_name='test') self.assertEquals(len(repo.head.get_object().parents), 2) self.assertEquals(repo.head.get_object().hex, cs.hash) # We want a commit in fastforward merges, hashes must be different self.assertNotEquals(ff_head.hash, cs.hash) self.assertTrue(os.path.isfile(ff_file))
def test_merge_fastforward_no_ff(self): git = GitCmd(self.cloned_from_repo) gitrepo = Repository(self.cloned_from_repo) gitrepo.update('master') gitrepo.branch('ff-branch') ff_file_name = 'ff-file.txt' ff_file = os.path.join(self.cloned_from_repo, ff_file_name) with open(ff_file, "w") as file: file_content = "Absurd content" file.write(file_content) gitrepo.add(ff_file_name) ff_head = gitrepo.commit(message="commit ff file") gitrepo.update('master') cs = gitrepo.merge(other_rev=ff_head, other_branch_name='test') self.assertEquals(len(git('log', '-1', pretty='%P').split()), 2) self.assertEquals(git('rev-parse', 'HEAD'), cs.hash) # We want a commit in fastforward merges, hashes must be different self.assertNotEquals(ff_head.hash, cs.hash) self.assertTrue(os.path.isfile(ff_file))
def test_merge_wrong_revision(self): gitrepo = Repository(self.cloned_from_repo) with self.assertRaises(RepositoryError): gitrepo.merge("wrong revision")
def test_merge_wrong_revision(self): gitrepo = Repository(self.cloned_from_repo) with self.assertRaises(RepositoryError): gitrepo.merge("wrong revision")