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

Fix cloning a repository with a particular branch to checkout #411

Merged
merged 1 commit 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/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def clone_repository(
# We need to keep the ref alive ourselves
checkout_branch_ref = None
if branch:
checkout_branch_ref = ffi.new('char []', branch)
checkout_branch_ref = ffi.new('char []', to_bytes(branch))
opts.checkout_branch = checkout_branch_ref

remote_name_ref = ffi.new('char []', to_bytes(remote_name))
Expand Down
23 changes: 11 additions & 12 deletions test/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,17 @@ def test_clone_with_credentials(self):

self.assertFalse(repo.is_empty)

def test_clone_with_checkout_branch(self):
# create a test case which isolates the remote
test_repo = clone_repository('./test/data/testrepo.git',
os.path.join(self._temp_dir, 'testrepo-orig.git'),
bare=True)
test_repo.create_branch('test', test_repo[test_repo.head.target])
repo = clone_repository(test_repo.path,
os.path.join(self._temp_dir, 'testrepo.git'),
checkout_branch='test', bare=True)
self.assertEqual(repo.lookup_reference('HEAD').target, 'refs/heads/test')

# FIXME The tests below are commented because they are broken:
#
# - test_clone_push_url: Passes, but does nothing useful.
Expand All @@ -437,8 +448,6 @@ def test_clone_with_credentials(self):
#
# - test_clone_push_spec: Passes, but does nothing useful.
#
# - test_clone_checkout_branch: Fails, because the test fixture does not
# have any branch named "test"

# def test_clone_push_url(self):
# repo_path = "./test/data/testrepo.git/"
Expand Down Expand Up @@ -470,15 +479,5 @@ def test_clone_with_credentials(self):
# # not sure how to test this either... couldn't find pushspec
# # self.assertEqual(repo.remotes[0].fetchspec, "refs/heads/test")

# def test_clone_checkout_branch(self):
# repo_path = "./test/data/testrepo.git/"
# repo = clone_repository(repo_path, self._temp_dir,
# checkout_branch="test")
# self.assertFalse(repo.is_empty)
# # FIXME: When pygit2 supports retrieving the current branch,
# # enable this test
# # self.assertEqual(repo.remotes[0].current_branch, "test")


if __name__ == '__main__':
unittest.main()