Implement addition of files to Config

This commit is contained in:
Martin Lenders 2012-06-08 16:00:59 +02:00
parent 068b833c87
commit fcacea310b
3 changed files with 35 additions and 0 deletions
include/pygit2
src/pygit2
test

@ -7,5 +7,6 @@
PyObject* Config_get_global_config(void);
PyObject* Config_get_system_config(void);
PyObject* Config_add_file(Config *self, PyObject *args);
#endif

@ -102,6 +102,25 @@ Config_get_system_config(void)
return Config_open(path);
}
PyObject *
Config_add_file(Config *self, PyObject *args)
{
int err;
char *path;
int priority;
if (!PyArg_ParseTuple(args, "si", &path, &priority))
return NULL;
err = git_config_add_file_ondisk(self->config, path, priority);
if (err < 0) {
Error_set_str(err, path);
return NULL;
}
Py_RETURN_NONE;
}
PyMethodDef Config_methods[] = {
{"get_system_config", (PyCFunction)Config_get_system_config,
METH_NOARGS | METH_STATIC,
@ -109,6 +128,8 @@ PyMethodDef Config_methods[] = {
{"get_global_config", (PyCFunction)Config_get_global_config,
METH_NOARGS | METH_STATIC,
"Return an object representing the global configuration file."},
{"add_file", (PyCFunction)Config_add_file, METH_VARARGS,
"Add a config file instance to an existing config."},
{NULL}
};

@ -57,6 +57,19 @@ class ConfigTest(utils.RepoTestCase):
self.assertNotEqual(config_write, None)
def test_add(self):
config = pygit2.Config.get_global_config()
new_file = open(config_filename, "w")
new_file.write("[this]\n\tthat = true\n")
new_file.write("[something \"other\"]\n\there = false")
new_file.close()
config.add_file(config_filename, 0)
os.remove(config_filename)
if __name__ == '__main__':
unittest.main()