From 629eea01e90907ed9ed82790d05c962f1d6ad47a Mon Sep 17 00:00:00 2001 From: djmattyg007 Date: Sat, 23 Aug 2014 11:23:17 +1000 Subject: [PATCH 1/2] Allow objects of type Branch to be passed to Repository.checkout() Branch inherits from Reference, so there's no reason why we shouldn't be able to pass a Branch object. --- pygit2/repository.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygit2/repository.py b/pygit2/repository.py index 45bc170..26f3033 100644 --- a/pygit2/repository.py +++ b/pygit2/repository.py @@ -263,7 +263,7 @@ class Repository(_Repository): return self.checkout_head(**kwargs) # Case 3: Reference - if type(refname) is Reference: + if isinstance(refname, Reference): reference = refname refname = refname.name else: From 14bcce0dcf74550bc546255c2d3218ff961044fb Mon Sep 17 00:00:00 2001 From: djmattyg007 Date: Sat, 23 Aug 2014 11:52:58 +1000 Subject: [PATCH 2/2] Add test for checking out local branches with a Branch object. This differs from the only other test which uses a Reference object. This test only succeeds because of the previous commit. --- test/test_repository.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/test_repository.py b/test/test_repository.py index cda846c..3014ef5 100644 --- a/test/test_repository.py +++ b/test/test_repository.py @@ -221,6 +221,25 @@ class RepositoryTest_II(utils.RepoTestCase): self.assertTrue('new' in head.tree) self.assertTrue('bye.txt' not in self.repo.status()) + def test_checkout_branch(self): + branch_i18n = self.repo.lookup_branch('i18n') + + # checkout i18n with conflicts and default strategy should + # not be possible + self.assertRaises(pygit2.GitError, self.repo.checkout, branch_i18n) + + # checkout i18n with GIT_CHECKOUT_FORCE + head = self.repo.head + head = self.repo[head.target] + self.assertTrue('new' not in head.tree) + self.repo.checkout(branch_i18n, strategy=pygit2.GIT_CHECKOUT_FORCE) + + head = self.repo.head + head = self.repo[head.target] + self.assertEqual(head.hex, branch_i18n.target.hex) + self.assertTrue('new' in head.tree) + self.assertTrue('bye.txt' not in self.repo.status()) + def test_checkout_index(self): # some changes to working dir with open(os.path.join(self.repo.workdir, 'hello.txt'), 'w') as f: