@@ -185,37 +185,46 @@ def _checkout_args_to_options(**kwargs):
185
185
copts = ffi .new ('git_checkout_options *' )
186
186
check_error (C .git_checkout_init_options (copts , 1 ))
187
187
188
+ # References we need to keep to strings and so forth
189
+ refs = []
190
+
188
191
# pygit2's default is SAFE_CREATE
189
192
copts .checkout_strategy = GIT_CHECKOUT_SAFE_CREATE
190
193
# and go through the arguments to see what the user wanted
191
- for k , v in kwargs .iteritems ():
192
- if k == 'strategy' :
193
- copts .checkout_strategy = v
194
+ strategy = kwargs .get ('strategy' )
195
+ if strategy :
196
+ copts .checkout_strategy = strategy
197
+
198
+ directory = kwargs .get ('directory' )
199
+ if directory :
200
+ target_dir = ffi .new ('char[]' , to_str (directory ))
201
+ refs .append (target_dir )
202
+ copts .target_directory = target_dir
194
203
195
- return copts
204
+ return copts , refs
196
205
197
206
def checkout_head (self , ** kwargs ):
198
207
"""Checkout HEAD
199
208
200
209
For arguments, see Repository.checkout().
201
210
"""
202
- copts = Repository ._checkout_args_to_options (** kwargs )
211
+ copts , refs = Repository ._checkout_args_to_options (** kwargs )
203
212
check_error (C .git_checkout_head (self ._repo , copts ))
204
213
205
214
def checkout_index (self , ** kwargs ):
206
215
"""Checkout the repository's index
207
216
208
217
For arguments, see Repository.checkout().
209
218
"""
210
- copts = Repository ._checkout_args_to_options (** kwargs )
219
+ copts , refs = Repository ._checkout_args_to_options (** kwargs )
211
220
check_error (C .git_checkout_index (self ._repo , ffi .NULL , copts ))
212
221
213
222
def checkout_tree (self , treeish , ** kwargs ):
214
223
"""Checkout the given treeish
215
224
216
225
For arguments, see Repository.checkout().
217
226
"""
218
- copts = Repository ._checkout_args_to_options (** kwargs )
227
+ copts , refs = Repository ._checkout_args_to_options (** kwargs )
219
228
cptr = ffi .new ('git_object **' )
220
229
ffi .buffer (cptr )[:] = treeish ._pointer [:]
221
230
@@ -242,6 +251,8 @@ def checkout(self, refname=None, **kwargs):
242
251
:param int strategy: A ``GIT_CHECKOUT_`` value. The default is
243
252
``GIT_CHECKOUT_SAFE_CREATE``.
244
253
254
+ :param str directory: Alternative checkout path to workdir.
255
+
245
256
"""
246
257
247
258
0 commit comments