summaryrefslogtreecommitdiff
path: root/src/config_file.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/config_file.c')
-rw-r--r--src/config_file.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/config_file.c b/src/config_file.c
index 5f8cffa14..147e85047 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -356,9 +356,14 @@ static int config_set(git_config_file *cfg, const char *name, const char *value)
}
/*
- * Otherwise, create it and stick it at the end of the queue.
+ * Otherwise, create it and stick it at the end of the queue. If
+ * value is NULL, we return an error, because you can't delete a
+ * variable that doesn't exist.
*/
+ if (value == NULL)
+ return git__throw(GIT_ENOTFOUND, "Can't delete non-exitent variable");
+
last_dot = strrchr(name, '.');
if (last_dot == NULL) {
return git__throw(GIT_EINVALIDTYPE, "Variables without section aren't allowed");
@@ -1011,8 +1016,15 @@ static int config_write(diskfile_backend *cfg, cvar_t *var)
break;
}
- /* Then replace the variable */
- error = git_filebuf_printf(&file, "\t%s = %s\n", var->name, var->value);
+ /*
+ * Then replace the variable. If the value is NULL, it
+ * means we want to delete it, so pretend everything went
+ * fine
+ */
+ if (var->value == NULL)
+ error = GIT_SUCCESS;
+ else
+ error = git_filebuf_printf(&file, "\t%s = %s\n", var->name, var->value);
if (error < GIT_SUCCESS) {
git__rethrow(error, "Failed to overwrite the variable");
break;