def test_pull(self):
        gitrepo1 = GitCmd(self.main_repo)
        gitrepo2 = GitCmd(self.cloned_from_repo)

        self.assertNotEqual(
            gitrepo1('rev-list', all=True).split(),
            gitrepo2('rev-list', all=True).split())

        repo = Repository(self.main_repo)

        # Pulling a branch
        self.assertNotIn('newbranch', [b.name for b in repo.get_branches()])
        repo.pull(remote=self.cloned_from_repo, branch='newbranch')
        self.assertIn('newbranch', [b.name for b in repo.get_branches()])

        # Pulling everything
        repo.pull(remote=self.cloned_from_repo)

        self.assertEqual(
            gitrepo1('rev-list', all=True).split().sort(),
            gitrepo2('rev-list', all=True).split().sort())

        gitrepo1_refs = list(gitrepo1('show-ref', _iter=True))
        gitrepo2_refs = list(gitrepo2('show-ref', _iter=True))

        # Check that all remote refs have been fetched
        for ref in gitrepo2_refs:
            self.assertIn(ref, gitrepo1_refs)

        # Pulling from a non existing remote
        with self.assertRaises(RepositoryError):
            repo.pull(remote='wrong repo')
    def test_pull(self):
        gitrepo1 = GitCmd(self.main_repo)
        gitrepo2 = GitCmd(self.cloned_from_repo)

        self.assertNotEqual(
            gitrepo1('rev-list', all=True).split(),
            gitrepo2('rev-list', all=True).split())

        repo = Repository(self.main_repo)

        # Pulling a branch
        self.assertNotIn('newbranch', [b.name for b in repo.get_branches()])
        repo.pull(remote=self.cloned_from_repo, branch='newbranch')
        self.assertIn('newbranch', [b.name for b in repo.get_branches()])

        # Pulling everything
        repo.pull(remote=self.cloned_from_repo)

        self.assertEqual(
            gitrepo1('rev-list', all=True).split().sort(),
            gitrepo2('rev-list', all=True).split().sort())

        gitrepo1_refs = list(gitrepo1('show-ref', _iter=True))
        gitrepo2_refs = list(gitrepo2('show-ref', _iter=True))

        # Check that all remote refs have been fetched
        for ref in gitrepo2_refs:
            self.assertIn(ref, gitrepo1_refs)

        # Pulling from a non existing remote
        with self.assertRaises(RepositoryError):
            repo.pull(remote='wrong repo')
    def test_exterminate_branch(self):
        branch_name = 'newbranch'
        gitrepo = Repository(self.cloned_from_repo)
        gitrepo_main = Repository(self.main_repo)
        gitrepo.update(branch_name)
        # Pushing the branch to the remote repo so we can check it's removed
        # remotely too
        gitrepo.push(None, self.main_repo, ref_name=branch_name)

        self.assertEquals(len(list(gitrepo.get_branches())), 2)
        self.assertEquals(len(list(gitrepo_main.get_branches())), 4)

        gitrepo.exterminate_branch(branch_name, None, self.main_repo)

        self.assertEquals(len(list(gitrepo.get_branches())), 1)
        self.assertEquals(len(list(gitrepo_main.get_branches())), 3)

        # Terminating a branch already terminated
        # it shouldn't do anything but warning with a message
        gitrepo.exterminate_branch(branch_name, None, self.main_repo)
    def test_exterminate_branch(self):
        branch_name = 'newbranch'
        gitrepo = Repository(self.cloned_from_repo)
        gitrepo_main = Repository(self.main_repo)
        gitrepo.update(branch_name)
        # Pushing the branch to the remote repo so we can check it's removed
        # remotely too
        gitrepo.push(None, self.main_repo, ref_name=branch_name)

        self.assertEquals(len(list(gitrepo.get_branches())), 2)
        self.assertEquals(len(list(gitrepo_main.get_branches())), 2)

        gitrepo.exterminate_branch(branch_name, None, self.main_repo)

        self.assertEquals(len(list(gitrepo.get_branches())), 1)
        self.assertEquals(len(list(gitrepo_main.get_branches())), 1)

        # Terminating a branch already terminated
        # it shouldn't do anything but warning with a message
        gitrepo.exterminate_branch(branch_name, None, self.main_repo)
    def test_get_branches(self):
        gitrepo = Repository(self.cloned_from_repo)
        branches = [b.name for b in gitrepo.get_branches()]

        self.assertListEqual(branches, ['master', 'newbranch'])
 def test_get_branches(self):
     repo = pygit2.Repository(self.cloned_from_repo)
     gitrepo = Repository(self.cloned_from_repo)
     branches = [b.name for b in gitrepo.get_branches()]
     self.assertListEqual(branches, repo.listall_branches())
    def test_get_branches(self):
        gitrepo = Repository(self.cloned_from_repo)
        branches = [b.name for b in gitrepo.get_branches()]

        self.assertListEqual(branches, ['master', 'newbranch'])