Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing of Branch objects to Repository.checkout() #408

Merged
merged 2 commits into from
Aug 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pygit2/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def checkout(self, refname=None, **kwargs):
return self.checkout_head(**kwargs)

# Case 3: Reference
if type(refname) is Reference:
if isinstance(refname, Reference):
reference = refname
refname = refname.name
else:
Expand Down
19 changes: 19 additions & 0 deletions test/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,25 @@ def test_checkout_ref(self):
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:
Expand Down