commit
ad7b86d9e6
@ -235,7 +235,7 @@ Config_foreach_callback_wrapper(const git_config_entry *entry, void *c_payload)
|
||||
if (!(py_result = PyObject_CallObject(py_callback,args)))
|
||||
return -1;
|
||||
|
||||
if (c_result = PyLong_AsLong(py_result) == -1)
|
||||
if ((c_result = PyLong_AsLong(py_result) == -1))
|
||||
return -1;
|
||||
|
||||
return c_result;
|
||||
|
@ -84,12 +84,11 @@ Index_add(Index *self, PyObject *args)
|
||||
{
|
||||
int err;
|
||||
const char *path;
|
||||
int stage=0;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s|i", &path, &stage))
|
||||
if (!PyArg_ParseTuple(args, "s", &path))
|
||||
return NULL;
|
||||
|
||||
err = git_index_add(self->index, path, stage);
|
||||
err = git_index_add_from_workdir(self->index, path);
|
||||
if (err < 0)
|
||||
return Error_set_str(err, path);
|
||||
|
||||
@ -281,7 +280,7 @@ Index_getitem(Index *self, PyObject *value)
|
||||
if (idx == -1)
|
||||
return NULL;
|
||||
|
||||
index_entry = git_index_get(self->index, idx);
|
||||
index_entry = git_index_get_byindex(self->index, idx);
|
||||
if (!index_entry) {
|
||||
PyErr_SetObject(PyExc_KeyError, value);
|
||||
return NULL;
|
||||
@ -290,27 +289,35 @@ Index_getitem(Index *self, PyObject *value)
|
||||
return wrap_index_entry(index_entry, self);
|
||||
}
|
||||
|
||||
PyObject *
|
||||
Index_remove(Index *self, PyObject *args)
|
||||
{
|
||||
int err;
|
||||
const char *path;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s", &path))
|
||||
return NULL;
|
||||
|
||||
err = git_index_remove(self->index, path, 0);
|
||||
if (err < 0) {
|
||||
Error_set(err);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
int
|
||||
Index_setitem(Index *self, PyObject *key, PyObject *value)
|
||||
{
|
||||
int err;
|
||||
int idx;
|
||||
|
||||
if (value) {
|
||||
if (value != NULL) {
|
||||
PyErr_SetString(PyExc_NotImplementedError,
|
||||
"set item on index not yet implemented");
|
||||
return -1;
|
||||
}
|
||||
|
||||
idx = Index_get_position(self, key);
|
||||
if (idx == -1)
|
||||
return -1;
|
||||
|
||||
err = git_index_remove(self->index, idx);
|
||||
if (err < 0) {
|
||||
Error_set(err);
|
||||
return -1;
|
||||
}
|
||||
if(Index_remove(self, Py_BuildValue("(N)", key)) == NULL)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -344,7 +351,7 @@ Index_write_tree(Index *self)
|
||||
git_oid oid;
|
||||
int err;
|
||||
|
||||
err = git_tree_create_fromindex(&oid, self->index);
|
||||
err = git_index_write_tree(&oid, self->index);
|
||||
if (err < 0)
|
||||
return Error_set(err);
|
||||
|
||||
@ -354,6 +361,8 @@ Index_write_tree(Index *self)
|
||||
PyMethodDef Index_methods[] = {
|
||||
{"add", (PyCFunction)Index_add, METH_VARARGS,
|
||||
"Add or update an index entry from a file in disk."},
|
||||
{"remove", (PyCFunction)Index_remove, METH_VARARGS,
|
||||
"Removes an entry from index."},
|
||||
{"clear", (PyCFunction)Index_clear, METH_NOARGS,
|
||||
"Clear the contents (all the entries) of an index object."},
|
||||
{"diff", (PyCFunction)Index_diff_tree, METH_VARARGS,
|
||||
@ -447,7 +456,7 @@ IndexIter_iternext(IndexIter *self)
|
||||
{
|
||||
git_index_entry *index_entry;
|
||||
|
||||
index_entry = git_index_get(self->owner->index, self->i);
|
||||
index_entry = git_index_get_byindex(self->owner->index, self->i);
|
||||
if (!index_entry)
|
||||
return NULL;
|
||||
|
||||
|
@ -151,7 +151,7 @@ class ConfigTest(utils.RepoTestCase):
|
||||
new_file.write("[this]\n\tthat = foobar\n\tthat = foobeer\n")
|
||||
new_file.close()
|
||||
|
||||
config.add_file(config_filename, 0)
|
||||
config.add_file(config_filename, 5)
|
||||
self.assertTrue('this.that' in config)
|
||||
config.set_multivar('this.that', '^.*beer', 'fool')
|
||||
l = config.get_multivar('this.that', 'fool')
|
||||
|
@ -80,7 +80,7 @@ class IndexTest(utils.RepoTestCase):
|
||||
|
||||
def test_write(self):
|
||||
index = self.repo.index
|
||||
index.add('bye.txt', 0)
|
||||
index.add('bye.txt')
|
||||
index.write()
|
||||
|
||||
index.clear()
|
||||
@ -133,7 +133,15 @@ class IndexTest(utils.RepoTestCase):
|
||||
self.assertEqual([x.hex for x in index],
|
||||
[x.hex for x in self.repo.index])
|
||||
|
||||
self.assertRaises(pygit2.GitError, lambda: index.add('bye.txt', 0))
|
||||
self.assertRaises(pygit2.GitError, lambda: index.add('bye.txt'))
|
||||
|
||||
def test_del(self):
|
||||
index = self.repo.index
|
||||
del index['hello.txt']
|
||||
|
||||
def test_remove(self):
|
||||
index = self.repo.index
|
||||
index.remove('hello.txt')
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user