def test_branch(self): gitrepo = Repository(self.cloned_from_repo) gitrepo.branch("test_branch") git = GitCmd(self.cloned_from_repo) # Checking we are in the branch self.assertEquals( git('rev-parse', 'test_branch'), git('rev-parse', 'HEAD')) self.assertEquals(git('rev-parse', '--abbrev-ref', 'HEAD'), 'test_branch') gitrepo.branch('newbranch') self.assertEquals( git('rev-parse', 'newbranch'), git('rev-parse', 'HEAD')) self.assertEquals(git('rev-parse', '--abbrev-ref', 'HEAD'), 'newbranch')
def test_branch(self): gitrepo = Repository(self.cloned_from_repo) gitrepo.branch("test_branch") git = GitCmd(self.cloned_from_repo) # Checking we are in the branch self.assertEquals(git('rev-parse', 'test_branch'), git('rev-parse', 'HEAD')) self.assertEquals(git('rev-parse', '--abbrev-ref', 'HEAD'), 'test_branch') gitrepo.branch('newbranch') self.assertEquals(git('rev-parse', 'newbranch'), git('rev-parse', 'HEAD')) self.assertEquals(git('rev-parse', '--abbrev-ref', 'HEAD'), 'newbranch')
def test_branch(self): gitrepo = Repository(self.cloned_from_repo) gitrepo.branch("test_branch") repo = pygit2.Repository(self.cloned_from_repo) # Checking branch exists self.assertIsNotNone(repo.lookup_reference('refs/heads/test_branch')) # Checking were in the branch head_hash = repo.head.get_object().hex self.assertEquals(repo.lookup_branch('test_branch').get_object().hex, head_hash) self.assertEquals(repo.head.name, "refs/heads/test_branch") # this does not throw exception, even though the branch already exists, # but this must switch to the branch gitrepo.branch("newbranch") head_hash = repo.head.get_object().hex self.assertEquals(repo.lookup_branch('newbranch').get_object().hex, head_hash) self.assertEquals(repo.head.name, "refs/heads/newbranch")
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(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) signature = Signature(user="******") ff_head = gitrepo.commit(message="commit ff file", signature=signature) gitrepo.update('master') cs = gitrepo.merge_fastforward( signature, other_rev=ff_head, other_branch_name='test') self.assertEquals(len(repo.head.get_object().parents), 1) self.assertEquals(repo.head.get_object().hex, cs.hash) self.assertEquals(ff_head.hash, cs.hash) self.assertTrue(os.path.isfile(ff_file))