Skip to content

Commit 63377aa

Browse files
committed
Properly initialize the clone options
libgit2 provides an initialization function to set sane defaults. Use that instead of setting the version by hand, as that's not the only thing it does. Using C.git_clone_init_options() sets the checkout strategy to SAFE, which will checkout the files after the clone, instead of the implicit NONE which we're setting by hand. This fixes #425,
1 parent 51da3b7 commit 63377aa

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

pygit2/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ def clone_repository(
151151
d['callback'] = credentials
152152
d_handle = ffi.new_handle(d)
153153

154+
# Perform the initialization with the version we compiled
155+
C.git_clone_init_options(opts, C.GIT_CLONE_OPTIONS_VERSION)
156+
154157
# We need to keep the ref alive ourselves
155158
checkout_branch_ref = None
156159
if branch:
@@ -160,11 +163,8 @@ def clone_repository(
160163
remote_name_ref = ffi.new('char []', to_bytes(remote_name))
161164
opts.remote_name = remote_name_ref
162165

163-
opts.version = 1
164166
opts.ignore_cert_errors = ignore_cert_errors
165167
opts.bare = bare
166-
opts.remote_callbacks.version = 1
167-
opts.checkout_opts.version = 1
168168
if credentials:
169169
opts.remote_callbacks.credentials = _credentials_cb
170170
opts.remote_callbacks.payload = d_handle

pygit2/decl.h

+3
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,9 @@ typedef struct git_clone_options {
353353
git_signature *signature;
354354
} git_clone_options;
355355

356+
#define GIT_CLONE_OPTIONS_VERSION ...
357+
int git_clone_init_options(git_clone_options *opts, unsigned int version);
358+
356359
int git_clone(git_repository **out,
357360
const char *url,
358361
const char *local_path,

0 commit comments

Comments
 (0)