Implement addition of files to Config
This commit is contained in:
@@ -7,5 +7,6 @@
|
|||||||
|
|
||||||
PyObject* Config_get_global_config(void);
|
PyObject* Config_get_global_config(void);
|
||||||
PyObject* Config_get_system_config(void);
|
PyObject* Config_get_system_config(void);
|
||||||
|
PyObject* Config_add_file(Config *self, PyObject *args);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -102,6 +102,25 @@ Config_get_system_config(void)
|
|||||||
return Config_open(path);
|
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[] = {
|
PyMethodDef Config_methods[] = {
|
||||||
{"get_system_config", (PyCFunction)Config_get_system_config,
|
{"get_system_config", (PyCFunction)Config_get_system_config,
|
||||||
METH_NOARGS | METH_STATIC,
|
METH_NOARGS | METH_STATIC,
|
||||||
@@ -109,6 +128,8 @@ PyMethodDef Config_methods[] = {
|
|||||||
{"get_global_config", (PyCFunction)Config_get_global_config,
|
{"get_global_config", (PyCFunction)Config_get_global_config,
|
||||||
METH_NOARGS | METH_STATIC,
|
METH_NOARGS | METH_STATIC,
|
||||||
"Return an object representing the global configuration file."},
|
"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}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -57,6 +57,19 @@ class ConfigTest(utils.RepoTestCase):
|
|||||||
|
|
||||||
self.assertNotEqual(config_write, None)
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Reference in New Issue
Block a user