new Repository.checkout method
This commit is contained in:
parent
270fa59e5b
commit
fbab2953de
@ -45,6 +45,7 @@ extern PyTypeObject TreeBuilderType;
|
||||
extern PyTypeObject ConfigType;
|
||||
extern PyTypeObject DiffType;
|
||||
extern PyTypeObject RemoteType;
|
||||
extern PyTypeObject ReferenceType;
|
||||
|
||||
git_otype
|
||||
int_to_loose_object_type(int type_id)
|
||||
@ -1066,6 +1067,44 @@ Repository_remotes__get__(Repository *self)
|
||||
}
|
||||
|
||||
|
||||
PyDoc_STRVAR(Repository_checkout__doc__,
|
||||
"checkout(reference:Reference, [strategy:int])\n"
|
||||
"\n"
|
||||
"Checks out a tree by a given reference and modifies the HEAD pointer.\n"
|
||||
"Standard checkout strategy is pygit2.GIT_CHECKOUT_SAFE_CREATE");
|
||||
|
||||
PyObject *
|
||||
Repository_checkout(Repository *self, PyObject *args)
|
||||
{
|
||||
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
|
||||
unsigned int strategy = GIT_CHECKOUT_SAFE_CREATE;
|
||||
Reference* ref;
|
||||
git_object* object;
|
||||
const git_oid* id;
|
||||
int err;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O!|I", &ReferenceType, &ref, &strategy))
|
||||
return NULL;
|
||||
|
||||
CHECK_REFERENCE(ref);
|
||||
|
||||
id = git_reference_target(ref->reference);
|
||||
err = git_object_lookup(&object, self->repo, id, GIT_OBJ_COMMIT);
|
||||
if(err == GIT_OK) {
|
||||
opts.checkout_strategy = strategy;
|
||||
err = git_checkout_tree(self->repo, object, &opts);
|
||||
if (err == GIT_OK)
|
||||
err = git_repository_set_head(self->repo,
|
||||
git_reference_name(ref->reference));
|
||||
}
|
||||
|
||||
if(err < 0)
|
||||
return Error_set(err);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
PyMethodDef Repository_methods[] = {
|
||||
METHOD(Repository, create_blob, METH_VARARGS),
|
||||
METHOD(Repository, create_blob_fromfile, METH_VARARGS),
|
||||
@ -1083,6 +1122,7 @@ PyMethodDef Repository_methods[] = {
|
||||
METHOD(Repository, status, METH_NOARGS),
|
||||
METHOD(Repository, status_file, METH_O),
|
||||
METHOD(Repository, create_remote, METH_VARARGS),
|
||||
METHOD(Repository, checkout, METH_VARARGS),
|
||||
{NULL}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user