t1300: `--unset-all` can leave an empty section behind (bug)
[gitweb.git] / config.c
index e617c2018d22b6d389548a3573d2deb2ec608b99..c55d6a564e256b56e8f3f41feac2e0045936d1e1 100644 (file)
--- a/config.c
+++ b/config.c
@@ -2617,6 +2617,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
                        store.seen = 1;
 
                for (i = 0, copy_begin = 0; i < store.seen; i++) {
+                       new_line = 0;
                        if (store.offset[i] == 0) {
                                store.offset[i] = copy_end = contents_sz;
                        } else if (store.state != KEY_SEEN) {
@@ -2624,7 +2625,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
                        } else
                                copy_end = find_beginning_of_line(
                                        contents, contents_sz,
-                                       store.offset[i]-2, &new_line);
+                                       store.offset[i], &new_line);
 
                        if (copy_end > 0 && contents[copy_end-1] != '\n')
                                new_line = 1;