checkout: add support for overriding the target directory
This commit is contained in:
@@ -185,21 +185,30 @@ class Repository(_Repository):
|
|||||||
copts = ffi.new('git_checkout_options *')
|
copts = ffi.new('git_checkout_options *')
|
||||||
check_error(C.git_checkout_init_options(copts, 1))
|
check_error(C.git_checkout_init_options(copts, 1))
|
||||||
|
|
||||||
|
# References we need to keep to strings and so forth
|
||||||
|
refs = []
|
||||||
|
|
||||||
# pygit2's default is SAFE_CREATE
|
# pygit2's default is SAFE_CREATE
|
||||||
copts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE
|
copts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE
|
||||||
# and go through the arguments to see what the user wanted
|
# and go through the arguments to see what the user wanted
|
||||||
for k, v in kwargs.iteritems():
|
strategy = kwargs.get('strategy')
|
||||||
if k == 'strategy':
|
if strategy:
|
||||||
copts.checkout_strategy = v
|
copts.checkout_strategy = strategy
|
||||||
|
|
||||||
return copts
|
directory = kwargs.get('directory')
|
||||||
|
if directory:
|
||||||
|
target_dir = ffi.new('char[]', to_str(directory))
|
||||||
|
refs.append(target_dir)
|
||||||
|
copts.target_directory = target_dir
|
||||||
|
|
||||||
|
return copts, refs
|
||||||
|
|
||||||
def checkout_head(self, **kwargs):
|
def checkout_head(self, **kwargs):
|
||||||
"""Checkout HEAD
|
"""Checkout HEAD
|
||||||
|
|
||||||
For arguments, see Repository.checkout().
|
For arguments, see Repository.checkout().
|
||||||
"""
|
"""
|
||||||
copts = Repository._checkout_args_to_options(**kwargs)
|
copts, refs = Repository._checkout_args_to_options(**kwargs)
|
||||||
check_error(C.git_checkout_head(self._repo, copts))
|
check_error(C.git_checkout_head(self._repo, copts))
|
||||||
|
|
||||||
def checkout_index(self, **kwargs):
|
def checkout_index(self, **kwargs):
|
||||||
@@ -207,7 +216,7 @@ class Repository(_Repository):
|
|||||||
|
|
||||||
For arguments, see Repository.checkout().
|
For arguments, see Repository.checkout().
|
||||||
"""
|
"""
|
||||||
copts = Repository._checkout_args_to_options(**kwargs)
|
copts, refs = Repository._checkout_args_to_options(**kwargs)
|
||||||
check_error(C.git_checkout_index(self._repo, ffi.NULL, copts))
|
check_error(C.git_checkout_index(self._repo, ffi.NULL, copts))
|
||||||
|
|
||||||
def checkout_tree(self, treeish, **kwargs):
|
def checkout_tree(self, treeish, **kwargs):
|
||||||
@@ -215,7 +224,7 @@ class Repository(_Repository):
|
|||||||
|
|
||||||
For arguments, see Repository.checkout().
|
For arguments, see Repository.checkout().
|
||||||
"""
|
"""
|
||||||
copts = Repository._checkout_args_to_options(**kwargs)
|
copts, refs = Repository._checkout_args_to_options(**kwargs)
|
||||||
cptr = ffi.new('git_object **')
|
cptr = ffi.new('git_object **')
|
||||||
ffi.buffer(cptr)[:] = treeish._pointer[:]
|
ffi.buffer(cptr)[:] = treeish._pointer[:]
|
||||||
|
|
||||||
@@ -242,6 +251,8 @@ class Repository(_Repository):
|
|||||||
:param int strategy: A ``GIT_CHECKOUT_`` value. The default is
|
:param int strategy: A ``GIT_CHECKOUT_`` value. The default is
|
||||||
``GIT_CHECKOUT_SAFE_CREATE``.
|
``GIT_CHECKOUT_SAFE_CREATE``.
|
||||||
|
|
||||||
|
:param str directory: Alternative checkout path to workdir.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
@@ -246,6 +246,14 @@ class RepositoryTest_II(utils.RepoTestCase):
|
|||||||
self.repo.checkout('HEAD', strategy=pygit2.GIT_CHECKOUT_FORCE)
|
self.repo.checkout('HEAD', strategy=pygit2.GIT_CHECKOUT_FORCE)
|
||||||
self.assertTrue('bye.txt' not in self.repo.status())
|
self.assertTrue('bye.txt' not in self.repo.status())
|
||||||
|
|
||||||
|
def test_checkout_alternative_dir(self):
|
||||||
|
ref_i18n = self.repo.lookup_reference('refs/heads/i18n')
|
||||||
|
extra_dir = os.path.join(self.repo.workdir, 'extra-dir')
|
||||||
|
os.mkdir(extra_dir)
|
||||||
|
self.assertTrue(len(os.listdir(extra_dir)) == 0)
|
||||||
|
self.repo.checkout(ref_i18n, directory=extra_dir)
|
||||||
|
self.assertFalse(len(os.listdir(extra_dir)) == 0)
|
||||||
|
|
||||||
def test_merge_base(self):
|
def test_merge_base(self):
|
||||||
commit = self.repo.merge_base(
|
commit = self.repo.merge_base(
|
||||||
'5ebeeebb320790caf276b9fc8b24546d63316533',
|
'5ebeeebb320790caf276b9fc8b24546d63316533',
|
||||||
|
Reference in New Issue
Block a user