Skip to content

Commit 617dd34

Browse files
committed
Merge remote-tracking branch 'carlos/checkout-branch'
2 parents dad9bc3 + b550027 commit 617dd34

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

pygit2/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def clone_repository(
154154
# We need to keep the ref alive ourselves
155155
checkout_branch_ref = None
156156
if branch:
157-
checkout_branch_ref = ffi.new('char []', branch)
157+
checkout_branch_ref = ffi.new('char []', to_bytes(branch))
158158
opts.checkout_branch = checkout_branch_ref
159159

160160
remote_name_ref = ffi.new('char []', to_bytes(remote_name))

test/test_repository.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,17 @@ def test_clone_with_credentials(self):
443443

444444
self.assertFalse(repo.is_empty)
445445

446+
def test_clone_with_checkout_branch(self):
447+
# create a test case which isolates the remote
448+
test_repo = clone_repository('./test/data/testrepo.git',
449+
os.path.join(self._temp_dir, 'testrepo-orig.git'),
450+
bare=True)
451+
test_repo.create_branch('test', test_repo[test_repo.head.target])
452+
repo = clone_repository(test_repo.path,
453+
os.path.join(self._temp_dir, 'testrepo.git'),
454+
checkout_branch='test', bare=True)
455+
self.assertEqual(repo.lookup_reference('HEAD').target, 'refs/heads/test')
456+
446457
# FIXME The tests below are commented because they are broken:
447458
#
448459
# - test_clone_push_url: Passes, but does nothing useful.
@@ -452,8 +463,6 @@ def test_clone_with_credentials(self):
452463
#
453464
# - test_clone_push_spec: Passes, but does nothing useful.
454465
#
455-
# - test_clone_checkout_branch: Fails, because the test fixture does not
456-
# have any branch named "test"
457466

458467
# def test_clone_push_url(self):
459468
# repo_path = "./test/data/testrepo.git/"
@@ -485,15 +494,5 @@ def test_clone_with_credentials(self):
485494
# # not sure how to test this either... couldn't find pushspec
486495
# # self.assertEqual(repo.remotes[0].fetchspec, "refs/heads/test")
487496

488-
# def test_clone_checkout_branch(self):
489-
# repo_path = "./test/data/testrepo.git/"
490-
# repo = clone_repository(repo_path, self._temp_dir,
491-
# checkout_branch="test")
492-
# self.assertFalse(repo.is_empty)
493-
# # FIXME: When pygit2 supports retrieving the current branch,
494-
# # enable this test
495-
# # self.assertEqual(repo.remotes[0].current_branch, "test")
496-
497-
498497
if __name__ == '__main__':
499498
unittest.main()

0 commit comments

Comments
 (0)