git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[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
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 2 of 6 in “advice API: simplification, small fixes, readability”
  1. 0/5 advice API: simplification, small fixes, readabilityÆvar Arnfjörð Bjarmason, Oct 4, 2021
  2. 2/5 advice output: emit empty lines as "hint:", not "hint: "Ævar Arnfjörð Bjarmason, Oct 4, 2021
  3. 1/5 advice.h: don't indent top-level enumÆvar Arnfjörð Bjarmason, Oct 4, 2021
  4. 3/5 advice.[ch]: remove advice.pushNonFastForward aliasÆvar Arnfjörð Bjarmason, Oct 4, 2021
  5. 4/5 advice API: revamp the API, againÆvar Arnfjörð Bjarmason, Oct 4, 2021
  6. 5/5 advice.[ch]: sort enum fields in alphabetical orderÆvar Arnfjörð Bjarmason, Oct 4, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.