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

Re: [PATCH] branch: advise about ref syntax rules

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 1, 2024, 18:06 UTC
Message-ID
<xmqq1q8t7roc.fsf@gitster.g>
In-Reply-To
<d275d1d179b90592ddd7b5da2ae4573b3f7a37b7.1709307442.git.code@khaugsbakk.name>
Kristoffer Haugsbakk <code@khaugsbakk.name> writes:
> Notes (series):
>     Hopefully I am using `advice.h` correctly here.
Let's see.
Show 7 quoted lines
> -	if (strbuf_check_branch_ref(ref, name))
> -		die(_("'%s' is not a valid branch name"), name);
> +	if (strbuf_check_branch_ref(ref, name)) {
> +		error(_("'%s' is not a valid branch name"), name);
> +		advise(_("See `man git check-ref-format`"));
> +		exit(1);
> +	}

This will give the message with "hint:" prefix, which is a good starting point.

The message is given unconditionally, without any way to turn it off. For those who ...

> git-branch(1) will error out if you give it a bad ref name. But the user
> might not understand why or what part of the name is illegal.

... do not understand why, it is helpful, but once they learned, it is one extra line of unwanted text. If you want to give it a way to squelch, see the comment before where enum advice_type is declared in advice.h header file. The callsites would become something like

	advise_if_enabled(ADVICE_VALID_REF_NAME,
		_("See `man git check-ref-format` for valid refname syntax."));

Another thing is that rewriting die() into error() + advice() + manual exit() is an anti-pattern these days.

	int code = die_message(_("'%s' is not a valid branch name"), name);
	advice_if_enabled(...); /* see above */
	exit(code);
In the same source file, you will find an existing example to mimic.
Thanks.
Previous: Kristoffer HaugsbakkNext: Kristoffer Haugsbakk
Message 2 of 28 in “branch: advise about ref syntax rules”
  1. branch: advise about ref syntax rulesKristoffer Haugsbakk, Mar 1, 2024
  2. Junio C HamanoMar 1, 2024
  3. Kristoffer HaugsbakkMar 1, 2024
  4. Junio C HamanoMar 1, 2024
  5. 0/1 advise about ref syntax rulesKristoffer Haugsbakk, Mar 3, 2024
  6. 1/1 branch: advise about ref syntax rulesKristoffer Haugsbakk, Mar 3, 2024
  7. Junio C HamanoMar 3, 2024
  8. Kristoffer HaugsbakkMar 3, 2024
  9. 0/5 advise about ref syntax rulesKristoffer Haugsbakk, Mar 4, 2024
  10. 1/5 t3200: improve test styleKristoffer Haugsbakk, Mar 4, 2024
  11. Junio C HamanoMar 5, 2024
  12. Kristoffer HaugsbakkMar 5, 2024
  13. Junio C HamanoMar 5, 2024
  14. 2/5 advice: make all entries stylistically consistentKristoffer Haugsbakk, Mar 4, 2024
  15. Junio C HamanoMar 4, 2024
  16. Kristoffer HaugsbakkMar 5, 2024
  17. 3/5 advice: use backticks for codeKristoffer Haugsbakk, Mar 4, 2024
  18. Junio C HamanoMar 4, 2024
  19. Kristoffer HaugsbakkMar 5, 2024
  20. 4/5 advice: use double quotes for regular quotingKristoffer Haugsbakk, Mar 4, 2024
  21. 5/5 branch: advise about ref syntax rulesKristoffer Haugsbakk, Mar 4, 2024
  22. 0/5 advise about ref syntax rulesKristoffer Haugsbakk, Mar 5, 2024
  23. 1/5 t3200: improve test styleKristoffer Haugsbakk, Mar 5, 2024
  24. 2/5 advice: make all entries stylistically consistentKristoffer Haugsbakk, Mar 5, 2024
  25. 3/5 advice: use backticks for verbatimKristoffer Haugsbakk, Mar 5, 2024
  26. 4/5 advice: use double quotes for regular quotingKristoffer Haugsbakk, Mar 5, 2024
  27. 5/5 branch: advise about ref syntax rulesKristoffer Haugsbakk, Mar 5, 2024
  28. Kristoffer HaugsbakkMar 3, 2024

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.