Merge branch 'ms/maint-config-error-at-eol-linecount'
When "git config" diagnoses an error in a configuration file and shows the line number for the offending line, it miscounted if the error was at the end of line. By Martin Stenberg * ms/maint-config-error-at-eol-linecount: config: report errors at the EOL with correct line number Conflicts: t/t1300-repo-config.sh
This commit is contained in:
commit
3f263099fc
13
config.c
13
config.c
@ -196,8 +196,10 @@ static char *parse_value(void)
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
int c = get_next_char();
|
int c = get_next_char();
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
if (quote)
|
if (quote) {
|
||||||
|
cf->linenr--;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
return cf->value.buf;
|
return cf->value.buf;
|
||||||
}
|
}
|
||||||
if (comment)
|
if (comment)
|
||||||
@ -287,7 +289,7 @@ static int get_extended_base_var(char *name, int baselen, int c)
|
|||||||
{
|
{
|
||||||
do {
|
do {
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
return -1;
|
goto error_incomplete_line;
|
||||||
c = get_next_char();
|
c = get_next_char();
|
||||||
} while (isspace(c));
|
} while (isspace(c));
|
||||||
|
|
||||||
@ -299,13 +301,13 @@ static int get_extended_base_var(char *name, int baselen, int c)
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
int c = get_next_char();
|
int c = get_next_char();
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
return -1;
|
goto error_incomplete_line;
|
||||||
if (c == '"')
|
if (c == '"')
|
||||||
break;
|
break;
|
||||||
if (c == '\\') {
|
if (c == '\\') {
|
||||||
c = get_next_char();
|
c = get_next_char();
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
return -1;
|
goto error_incomplete_line;
|
||||||
}
|
}
|
||||||
name[baselen++] = c;
|
name[baselen++] = c;
|
||||||
if (baselen > MAXNAME / 2)
|
if (baselen > MAXNAME / 2)
|
||||||
@ -316,6 +318,9 @@ static int get_extended_base_var(char *name, int baselen, int c)
|
|||||||
if (get_next_char() != ']')
|
if (get_next_char() != ']')
|
||||||
return -1;
|
return -1;
|
||||||
return baselen;
|
return baselen;
|
||||||
|
error_incomplete_line:
|
||||||
|
cf->linenr--;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_base_var(char *name)
|
static int get_base_var(char *name)
|
||||||
|
@ -985,4 +985,35 @@ test_expect_success 'git config --edit respects core.editor' '
|
|||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
# 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
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user