commit de51a12a5befe30cf15a089998d0136d52856dc2 from: Omar Polo date: Tue Feb 21 15:02:58 2023 UTC gitconfig.c: look for comments after trimming the start of the line This fixes the (harmless) errors raised by gitconfig.c on indented comment lines and adds a test case for it. Reported by James Cook, thanks! ok stsp@ commit - 1dda2072ee3eb04988c80d2a72522e489a606914 commit + de51a12a5befe30cf15a089998d0136d52856dc2 blob - de21419fc5de70a18f027cbc1a65c38a5049e912 blob + 5af728df10a622bad125d0bc41ba804acfc9ccca --- lib/gitconfig.c +++ lib/gitconfig.c @@ -221,10 +221,6 @@ conf_parse_line(char **section, struct got_gitconfig * char *val; size_t i; int j; - - /* Lines starting with '#' or ';' are comments. */ - if (*line == '#' || *line == ';') - return NULL; /* '[section]' parsing... */ if (*line == '[') { @@ -247,6 +243,10 @@ conf_parse_line(char **section, struct got_gitconfig * line++; sz--; } + + /* Lines starting with '#' or ';' are comments. */ + if (*line == '#' || *line == ';') + return NULL; /* Deal with assignments. */ for (i = 0; i < sz; i++) blob - 62bcb9f3f02f060aa7096a6fd0d8eb9f6ded5382 blob + 8ab732f77ce0d79d8a050bfedb50712fa26428d2 --- regress/cmdline/commit.sh +++ regress/cmdline/commit.sh @@ -982,6 +982,9 @@ test_commit_gitconfig_author() { # retry with spaces in the git config ed -s "$testroot/repo/.git/config" </dev/null) + got commit -m 'test gitconfig author again' \ + >/dev/null 2>$testroot/stderr) + ret=$? + if [ $ret -ne 0 ]; then + test_done "$testroot" "$ret" + return 1 + fi + + # shouldn't have triggered any parsing error + echo -n > $testroot/stderr.expected + cmp -s $testroot/stderr.expected $testroot/stderr ret=$? if [ $ret -ne 0 ]; then + diff -u $testroot/stderr.expected $testroot/stderr test_done "$testroot" "$ret" return 1 fi