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

[PATCH v2 4/4] tag: Prevent users from creating tags named "refs" or "refs/*"

From
IRIngo Rohloff <ingo.rohloff@lauterbach.com>
Date
Nov 7, 2019, 19:07 UTC
Message-ID
<20191107190750.26674-5-ingo.rohloff@lauterbach.com>
In-Reply-To
<20191107190750.26674-1-ingo.rohloff@lauterbach.com>
To explain the intention, here is an example:
A user executes
   git tag -m "a tag" refs/heads/master
after this operation
   git log refs/heads/master
will very likely complain that this reference is ambiguous.

The reason is, that you now very likely have the following two references which both match:

   refs/heads/master
   refs/tags/refs/heads/master
git cannot decide which of the two references is meant.
By preventing the creation of tags which are named
  refs  or  refs/*
this issue is circumvented:
  git log refs/*
will never refer to a tag located under
  refs/tags/refs/*
because such a tag should not exist.
Signed-off-by: Ingo Rohloff <ingo.rohloff@lauterbach.com>
---
 builtin/tag.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/builtin/tag.c b/builtin/tag.c
index e0a4c25382..c818fe3fcd 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -537,6 +537,9 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 
 	tag = argv[0];
 
+	if (!cmdmode && newname_has_bad_prefix(tag))
+		die(_("Invalid new tag name: '%s'"), tag);
+
 	object_ref = argc == 2 ? argv[1] : "HEAD";
 	if (argc > 2)
 		die(_("too many params"));
-- 
2.24.0
Previous: Ingo RohloffNext: Ingo Rohloff
Message 11 of 12 in “branch: Forbid to create local branches with confusing names”
  1. branch: Forbid to create local branches with confusing namesIngo Rohloff, Nov 6, 2019
  2. Johannes SchindelinNov 6, 2019
  3. Ingo RohloffNov 7, 2019
  4. Junio C HamanoNov 7, 2019
  5. Ingo RohloffNov 7, 2019
  6. Junio C HamanoNov 8, 2019
  7. Ingo RohloffNov 8, 2019
  8. 0/4 Do not create new refnames "refs" or "refs/*"Ingo Rohloff, Nov 7, 2019
  9. 1/4 refs: new function newname_has_bad_prefixIngo Rohloff, Nov 7, 2019
  10. 3/4 remote: Prevent users from creating remotes named "refs" or "refs/*"Ingo Rohloff, Nov 7, 2019
  11. 4/4 tag: Prevent users from creating tags named "refs" or "refs/*"Ingo Rohloff, Nov 7, 2019
  12. 2/4 branch: Prevent creation of local branches named "refs" or "refs/*"Ingo Rohloff, Nov 7, 2019

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.