Earlier, calling git-repo-config core.hello on a .git/config like this: [core] hello = world ; a comment would yield "world " (i.e. with a trailing space). Signed-off-by: Johannes Schindelin <Johannes.Schindelin@xxxxxx> --- I wrote: > Strange thing I realized: A value is white-space-trimmed at the end > only if the line does not end with a comment. This fact is accounted > for in the new tests. It actually was a buglet in parse_value(), so it was not only repo-config which was affected. Obviously, this patch comes on top of the --get-regexp patch, but feel free to apply without that. config.c | 12 ++++++------ t/t1300-repo-config.sh | 8 ++++++-- 2 files changed, 12 insertions(+), 8 deletions(-) bb874fdd7a55b7adc229ee9eb1b59e5852b41594 diff --git a/config.c b/config.c index 4e1f0c2..253c48a 100644 --- a/config.c +++ b/config.c @@ -60,6 +60,12 @@ static char *parse_value(void) space = 1; continue; } + if (!quote) { + if (c == ';' || c == '#') { + comment = 1; + continue; + } + } if (space) { if (len) value[len++] = ' '; @@ -93,12 +99,6 @@ static char *parse_value(void) quote = 1-quote; continue; } - if (!quote) { - if (c == ';' || c == '#') { - comment = 1; - continue; - } - } value[len++] = c; } } diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index 52e8e33..e3ab661 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -247,8 +247,12 @@ EOF test_expect_success 'hierarchical section value' 'cmp .git/config expect' +value="$(git-repo-config beta.noindent)" + +test_expect_success 'trim before comment' "test \"$value\" = sillyValue" + cat > expect << EOF -beta.noindent=sillyValue +beta.noindent=sillyValue nextsection.nonewline=wow2 for me 123456.a123=987 1.2.3.alpha=beta @@ -258,7 +262,7 @@ test_expect_success 'working --list' \ 'git-repo-config --list > output && cmp output expect' cat > expect << EOF -beta.noindent sillyValue +beta.noindent sillyValue nextsection.nonewline wow2 for me EOF -- 1.3.1.g259f - : send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html