config --replace-all: avoid extra line breaks
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Tue, 3 Apr 2018 16:28:14 +0000 (18:28 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 5 Apr 2018 23:30:03 +0000 (08:30 +0900)
When replacing multiple config entries at once, we did not re-set the
flag that indicates whether we need to insert a new-line before the new
entry. As a consequence, an extra new-line was inserted under certain
circumstances.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
config.c
t/t1300-config.sh
index 4c8571ab33bd6572a6035d7f3408f77cdfeb8dbf..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) {
index cef816325b6ba0c5504f8d85536a48ad7a56cbfa..8f37ffadb1f19fba6b9ddd38403164002d37cb78 100755 (executable)
@@ -1588,7 +1588,7 @@ test_expect_success '--local requires a repo' '
        test_expect_code 128 nongit git config --local foo.bar
 '
 
-test_expect_failure '--replace-all does not invent newlines' '
+test_expect_success '--replace-all does not invent newlines' '
        q_to_tab >.git/config <<-\EOF &&
        [abc]key
        QkeepSection