From: Junio C Hamano Date: Mon, 26 Mar 2012 19:10:05 +0000 (-0700) Subject: Merge branch 'ms/maint-config-error-at-eol-linecount' into maint X-Git-Tag: v1.7.9.5~3 X-Git-Url: https://git.tokkee.org/?p=git.git;a=commitdiff_plain;h=ed6ce4382b5cb34e98ca3db2f19de82a037da322;hp=a12c6b0149e3dadd0701dac4fd0ba2463d251650 Merge branch 'ms/maint-config-error-at-eol-linecount' into maint * ms/maint-config-error-at-eol-linecount: config: report errors at the EOL with correct line number --- diff --git a/config.c b/config.c index 40f9c6d10..818ba6df0 100644 --- a/config.c +++ b/config.c @@ -135,8 +135,10 @@ static char *parse_value(void) for (;;) { int c = get_next_char(); if (c == '\n') { - if (quote) + if (quote) { + cf->linenr--; return NULL; + } return cf->value.buf; } if (comment) @@ -226,7 +228,7 @@ static int get_extended_base_var(char *name, int baselen, int c) { do { if (c == '\n') - return -1; + goto error_incomplete_line; c = get_next_char(); } while (isspace(c)); @@ -238,13 +240,13 @@ static int get_extended_base_var(char *name, int baselen, int c) for (;;) { int c = get_next_char(); if (c == '\n') - return -1; + goto error_incomplete_line; if (c == '"') break; if (c == '\\') { c = get_next_char(); if (c == '\n') - return -1; + goto error_incomplete_line; } name[baselen++] = c; if (baselen > MAXNAME / 2) @@ -255,6 +257,9 @@ static int get_extended_base_var(char *name, int baselen, int c) if (get_next_char() != ']') return -1; return baselen; +error_incomplete_line: + cf->linenr--; + return -1; } static int get_base_var(char *name) diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index 0690e0edf..728a96566 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -960,4 +960,35 @@ test_expect_success 'git -c complains about empty key and value' ' test_must_fail git -c "" rev-parse ' +# malformed configuration files +test_expect_success 'barf on syntax error' ' + cat >.git/config <<-\EOF && + # broken section line + [section] + key garbage + EOF + test_must_fail git config --get section.key >actual 2>error && + grep " line 3 " error +' + +test_expect_success 'barf on incomplete section header' ' + cat >.git/config <<-\EOF && + # broken section line + [section + key = value + EOF + test_must_fail git config --get section.key >actual 2>error && + grep " line 2 " error +' + +test_expect_success 'barf on incomplete string' ' + cat >.git/config <<-\EOF && + # broken section line + [section] + key = "value string + EOF + test_must_fail git config --get section.key >actual 2>error && + grep " line 3 " error +' + test_done