[PATCH 2/5] advice output: emit empty lines as "hint:", not "hint: "
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Oct 4, 2021, 01:58 UTC
- Message-ID
- <patch-2.5-5b5754ebfd2-20211004T015432Z-avarab@gmail.com>
- In-Reply-To
- <cover-0.5-00000000000-20211004T015432Z-avarab@gmail.com>
Let's not needlessly add this trailing whitespace to empty "hint:" lines, this makes copy/pasting them better, and also makes the tests more straightforward.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- advice.c | 9 +++++++-- t/t7004-tag.sh | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/advice.c b/advice.c index 2f5499a5e18..9691c7e7899 100644 --- a/advice.c +++ b/advice.c @@ -90,10 +90,15 @@ static void vadvise(const char *advice, int display_instructions, strbuf_addf(&buf, turn_off_instructions, key); for (cp = buf.buf; *cp; cp = np) { + int len; + np = strchrnul(cp, '\n'); - fprintf(stderr, _("%shint: %.*s%s\n"), + len = np - cp; + + fprintf(stderr, _("%shint:%s%.*s%s\n"), advise_get_color(ADVICE_COLOR_HINT), - (int)(np - cp), cp, + len ? " " : "", + len, cp, advise_get_color(ADVICE_COLOR_RESET)); if (*np) np++; diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh index 082be85dffc..a7041e64ccf 100755 --- a/t/t7004-tag.sh +++ b/t/t7004-tag.sh @@ -1749,10 +1749,10 @@ test_expect_success '--points-at finds annotated tags of tags' ' ' test_expect_success 'recursive tagging should give advice' ' - sed -e "s/|$//" <<-EOF >expect && + cat <<-EOF >expect && hint: You have created a nested tag. The object referred to by your new tag is hint: already a tag. If you meant to tag the object that it points to, use: - hint: | + hint: hint: git tag -f nested annotated-v4.0^{} hint: Disable this message with "git config advice.nestedTag false" EOF
-- 2.33.0.1404.g7bcfc82b295