Merge remote-tracking branch 'esc/feature/init_repository_keywordargs'
This commit is contained in:
commit
6fcd19eb0b
@ -7,9 +7,17 @@ The repository
|
|||||||
This is how to create non-bare repository::
|
This is how to create non-bare repository::
|
||||||
|
|
||||||
>>> from pygit2 import init_repository
|
>>> from pygit2 import init_repository
|
||||||
>>> bare = False
|
>>> repo = init_repository('test')
|
||||||
>>> repo = init_repository('test', bare)
|
|
||||||
|
|
||||||
|
And this is how to create a bare repository::
|
||||||
|
|
||||||
|
>>> from pygit2 import init_repository
|
||||||
|
>>> repo = init_repository('test', bare=True)
|
||||||
|
|
||||||
|
But one can also do::
|
||||||
|
|
||||||
|
>>> from pygit2 import init_repository
|
||||||
|
>>> repo = init_repository('test', True)
|
||||||
|
|
||||||
.. autofunction:: pygit2.discover_repository
|
.. autofunction:: pygit2.discover_repository
|
||||||
|
|
||||||
|
12
src/pygit2.c
12
src/pygit2.c
@ -62,20 +62,20 @@ extern PyTypeObject RemoteType;
|
|||||||
|
|
||||||
|
|
||||||
PyDoc_STRVAR(init_repository__doc__,
|
PyDoc_STRVAR(init_repository__doc__,
|
||||||
"init_repository(path, bare) -> Repository\n"
|
"init_repository(path, bare=False) -> Repository\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Creates a new Git repository in the given path.");
|
"Creates a new Git repository in the given path.");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
init_repository(PyObject *self, PyObject *args)
|
init_repository(PyObject *self, PyObject *args, PyObject *kw) {
|
||||||
{
|
|
||||||
git_repository *repo;
|
git_repository *repo;
|
||||||
Repository *py_repo;
|
Repository *py_repo;
|
||||||
const char *path;
|
const char *path;
|
||||||
unsigned int bare;
|
unsigned int bare = 0;
|
||||||
int err;
|
int err;
|
||||||
|
static char * kwlist[] = {"path", "bare", NULL};
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "sI", &path, &bare))
|
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|I", kwlist, &path, &bare))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
err = git_repository_init(&repo, path, bare);
|
err = git_repository_init(&repo, path, bare);
|
||||||
@ -168,7 +168,7 @@ hash(PyObject *self, PyObject *args)
|
|||||||
|
|
||||||
|
|
||||||
PyMethodDef module_methods[] = {
|
PyMethodDef module_methods[] = {
|
||||||
{"init_repository", init_repository, METH_VARARGS, init_repository__doc__},
|
{"init_repository", init_repository, METH_VARARGS|METH_KEYWORDS, init_repository__doc__},
|
||||||
{"discover_repository", discover_repository, METH_VARARGS,
|
{"discover_repository", discover_repository, METH_VARARGS,
|
||||||
discover_repository__doc__},
|
discover_repository__doc__},
|
||||||
{"hashfile", hashfile, METH_VARARGS, hashfile__doc__},
|
{"hashfile", hashfile, METH_VARARGS, hashfile__doc__},
|
||||||
|
@ -234,6 +234,29 @@ class NewRepositoryTest(utils.NoRepoTestCase):
|
|||||||
|
|
||||||
assert os.path.exists(os.path.join(self._temp_dir, '.git'))
|
assert os.path.exists(os.path.join(self._temp_dir, '.git'))
|
||||||
|
|
||||||
|
class InitRepositoryTest(utils.NoRepoTestCase):
|
||||||
|
# under the assumption that repo.is_bare works
|
||||||
|
|
||||||
|
def test_no_arg(self):
|
||||||
|
repo = init_repository(self._temp_dir)
|
||||||
|
self.assertFalse(repo.is_bare)
|
||||||
|
|
||||||
|
def test_pos_arg_false(self):
|
||||||
|
repo = init_repository(self._temp_dir, False)
|
||||||
|
self.assertFalse(repo.is_bare)
|
||||||
|
|
||||||
|
def test_pos_arg_true(self):
|
||||||
|
repo = init_repository(self._temp_dir, True)
|
||||||
|
self.assertTrue(repo.is_bare)
|
||||||
|
|
||||||
|
def test_keyword_arg_false(self):
|
||||||
|
repo = init_repository(self._temp_dir, bare=False)
|
||||||
|
self.assertFalse(repo.is_bare)
|
||||||
|
|
||||||
|
def test_keyword_arg_true(self):
|
||||||
|
repo = init_repository(self._temp_dir, bare=True)
|
||||||
|
self.assertTrue(repo.is_bare)
|
||||||
|
|
||||||
class DiscoverRepositoryTest(utils.NoRepoTestCase):
|
class DiscoverRepositoryTest(utils.NoRepoTestCase):
|
||||||
def test_discover_repo(self):
|
def test_discover_repo(self):
|
||||||
repo = init_repository(self._temp_dir, False)
|
repo = init_repository(self._temp_dir, False)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user