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

[PATCH v2 0/1] advise about ref syntax rules

From
Kristoffer Haugsbakk <code@khaugsbakk.name>
Date
Mar 3, 2024, 18:58 UTC
Message-ID
<cover.1709491818.git.code@khaugsbakk.name>
In-Reply-To
<d275d1d179b90592ddd7b5da2ae4573b3f7a37b7.1709307442.git.code@khaugsbakk.name>

Point the user towards the ref/branch name syntax rules if they give an invalid name.

§ git-replace(1)
I did not add a hint for a similar message in `builtin/replace.c`.

`builtin/replace.c` has an error message in `check_ref_valid` for an invalid ref name:

``` return error(_("'%s' is not a valid ref name"), ref->buf); ```

But there doesn’t seem to be a point to placing a hint here.

The preceding calls to `repo_get_oid` will catch both missing refs and existing refs with invalid names:

```
 if (repo_get_oid(r, refname, &object))
	 return error(_("failed to resolve '%s' as a valid ref"), refname);
```
Like for example this:

``` $ printf $(git rev-parse @~) > .git/refs/heads/hello..goodbye $ git replace @ hello..goodbye error: failed to resolve 'hello..goodbye' as a valid ref […] $ git replace @ non-existing error: failed to resolve 'non-existing' as a valid ref ```

§ Alternatives (to this change)

While working on this I also thought that it might be nice to have a man page `gitrefsyntax`. That one could use a lot of the content from `man git check-ref-format` verbatim. Then the hint could point towards that man page. And it seems that AsciiDoc supports _includes_ which means that the rules don’t have to be duplicated between the two man pages.

§ Changes in v2
• Make the advise optional via configuration
  • At first I thought that this wasn’t needed but I imagine the advice
    could get repetitive for typos and such
• Propagate error properly with `die_message(…)` instead of `exit(1)`
• Flesh out commit message a bit
Kristoffer Haugsbakk (1):
  branch: advise about ref syntax rules
 Documentation/config/advice.txt |  3 +++
 advice.c                        |  1 +
 advice.h                        |  1 +
 branch.c                        |  8 ++++++--
 builtin/branch.c                |  8 ++++++--
 t/t3200-branch.sh               | 11 +++++++++++
 6 files changed, 28 insertions(+), 4 deletions(-)
-- 
2.44.0.64.g52b67adbeb2
Previous: Junio C HamanoNext: Kristoffer Haugsbakk
Message 5 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.