summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a4c0d46)
raw | patch | inline | side by side (parent: a4c0d46)
author | Alex Vandiver <alex@chmrr.net> | |
Fri, 24 Jul 2009 21:21:44 +0000 (17:21 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sat, 25 Jul 2009 06:42:44 +0000 (23:42 -0700) |
Signed-off-by: Alex Vandiver <alex@chmrr.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
config.c | patch | blob | history | |
t/t1300-repo-config.sh | patch | blob | history |
diff --git a/config.c b/config.c
index 8d0e549976d6d2081e62c5de3a3da4085bb0c99e..738b24419dcd0deb4bb0700f25f8984b8862d14f 100644 (file)
--- a/config.c
+++ b/config.c
while (fgets(buf, sizeof(buf), config_file)) {
int i;
int length;
+ char *output = buf;
for (i = 0; buf[i] && isspace(buf[i]); i++)
; /* do nothing */
if (buf[i] == '[') {
ret = write_error(lock->filename);
goto out;
}
- continue;
+ /*
+ * We wrote out the new section, with
+ * a newline, now skip the old
+ * section's length
+ */
+ output += offset + i;
+ if (strlen(output) > 0) {
+ /*
+ * More content means there's
+ * a declaration to put on the
+ * next line; indent with a
+ * tab
+ */
+ output -= 1;
+ output[0] = '\t';
+ }
}
remove = 0;
}
if (remove)
continue;
- length = strlen(buf);
- if (write_in_full(out_fd, buf, length) != length) {
+ length = strlen(output);
+ if (write_in_full(out_fd, output, length) != length) {
ret = write_error(lock->filename);
goto out;
}
diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
index 43ea283242c4afc25e53d4a8c894140793649717..8c43dcde8ab8d491cbe047903fa065f6550de4d6 100755 (executable)
--- a/t/t1300-repo-config.sh
+++ b/t/t1300-repo-config.sh
test_expect_success "rename succeeded" "test_cmp expect .git/config"
+cat >> .git/config << EOF
+[branch "vier"] z = 1
+EOF
+
+test_expect_success "rename a section with a var on the same line" \
+ 'git config --rename-section branch.vier branch.zwei'
+
+cat > expect << EOF
+# Hallo
+ #Bello
+[branch "zwei"]
+ x = 1
+[branch "zwei"]
+ y = 1
+[branch "drei"]
+weird
+[branch "zwei"]
+ z = 1
+EOF
+
+test_expect_success "rename succeeded" "test_cmp expect .git/config"
+
cat >> .git/config << EOF
[branch "zwei"] a = 1 [branch "vier"]
EOF