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

[PATCHv2 04/10] remote: Reject remote names containing '/'

From
Johan Herland <johan@herland.net>
Date
May 11, 2013, 16:21 UTC
Message-ID
<1368289280-30337-5-git-send-email-johan@herland.net>
In-Reply-To
<1368289280-30337-1-git-send-email-johan@herland.net>

Although we definitely support and encourage use of multi-level branch names, we have never conciously tried to give support for multi-level remote names. Currently, they are allowed, but there is no evidence that they are commonly used.

Now, they do provide a source of problems when trying to expand the "$nick/$name" shorthand notation (where $nick matches a remote name) into a full refname. Consider the shorthand "foo/bar/baz": Does this parse as $nick = foo, $name = bar/baz, or $nick = foo/bar, $name = baz?

Since we need to be unambiguous about these things, we hereby declare that a remote name shall never contain a '/' character, and that the only correct way to parse "foo/bar/baz" is $nick = foo, $name = bar/baz.

This patch teaches 'git remote' to reject remote names with slashes, and adds tests verifying this.

Signed-off-by: Johan Herland <johan@herland.net>
---
 builtin/remote.c  |  4 ++--
 t/t5505-remote.sh | 12 ++++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/builtin/remote.c b/builtin/remote.c
index 5e54d36..6e7369d 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -195,7 +195,7 @@ static int add(int argc, const char **argv)
 		die(_("remote %s already exists."), name);
 
 	strbuf_addf(&buf2, "refs/heads/test:refs/remotes/%s/test", name);
-	if (!valid_fetch_refspec(buf2.buf))
+	if (!valid_fetch_refspec(buf2.buf) || strchr(name, '/'))
 		die(_("'%s' is not a valid remote name"), name);
 
 	strbuf_addf(&buf, "remote.%s.url", name);
@@ -646,7 +646,7 @@ static int mv(int argc, const char **argv)
 		die(_("remote %s already exists."), rename.new);
 
 	strbuf_addf(&buf, "refs/heads/test:refs/remotes/%s/test", rename.new);
-	if (!valid_fetch_refspec(buf.buf))
+	if (!valid_fetch_refspec(buf.buf) || strchr(rename.new, '/'))
 		die(_("'%s' is not a valid remote name"), rename.new);
 
 	strbuf_reset(&buf);
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index dd10ff0..f7098fe 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -621,6 +621,12 @@ test_expect_success 'reject adding remote with an invalid name' '
 
 '
 
+test_expect_success 'reject adding remote with slash in name' '
+
+	test_must_fail git remote add multi/level .
+
+'
+
 # The first three test if the tracking branches are properly renamed,
 # the last two ones check if the config is updated.
 
@@ -668,6 +674,12 @@ test_expect_success 'rename a remote with name prefix of other remote' '
 
 '
 
+test_expect_success 'rename a remote with slash in name' '
+
+	test_must_fail git remote rename upstream up/stream
+
+'
+
 cat > remotes_origin << EOF
 URL: $(pwd)/one
 Push: refs/heads/master:refs/heads/upstream
-- 
1.8.1.3.704.g33f7d4f
Previous: Eric WongNext: Eric Sunshine
Message 16 of 31 in “[PATCHv2 00/10] Prepare for alternative remote-tracking branch location”
  1. Johan HerlandMay 11, 2013
  2. 01/10 t7900: Start testing usability of namespaced remote refsJohan Herland, May 11, 2013
  3. 02/10 t7900: Demonstrate failure to expand "$peer/$branch" according to refspecsJohan Herland, May 11, 2013
  4. 03/10 refs.c: Refactor code for mapping between shorthand names and full refnamesJohan Herland, May 11, 2013
  5. Junio C HamanoMay 13, 2013
  6. Johan HerlandMay 13, 2013
  7. Junio C HamanoMay 13, 2013
  8. Junio C HamanoMay 13, 2013
  9. Johan HerlandMay 14, 2013
  10. Junio C HamanoMay 14, 2013
  11. Michael HaggertyMay 15, 2013
  12. Johan HerlandMay 15, 2013
  13. Johan HerlandMay 15, 2013
  14. Junio C HamanoMay 15, 2013
  15. Eric WongMay 15, 2013
  16. 04/10 remote: Reject remote names containing '/'Johan Herland, May 11, 2013
  17. Eric SunshineMay 13, 2013
  18. Johan HerlandMay 13, 2013
  19. Junio C HamanoMay 13, 2013
  20. Johan HerlandMay 13, 2013
  21. Ramkumar RamachandraMay 16, 2013
  22. Johan HerlandMay 16, 2013
  23. Ramkumar RamachandraMay 16, 2013
  24. 05/10 refs.c: Add support for expanding/shortening refs in refs/peers/*Johan Herland, May 11, 2013
  25. 06/10 t7900: Test git branch -r/-a output w/remote-tracking branches in refs/peers/*Johan Herland, May 11, 2013
  26. 07/10 t3203: Add testcase for fix in 1603ade81352a526ccb206f41ff81ecbc855df2dJohan Herland, May 11, 2013
  27. 08/10 builtin/branch.c: Refactor ref_item.name and .dest into strbufsJohan Herland, May 11, 2013
  28. 09/10 builtin/branch.c: Refactor "remotes/" prepending to remote-tracking branchesJohan Herland, May 11, 2013
  29. 10/10 branch: Fix display of remote branches in refs/peers/*Johan Herland, May 11, 2013
  30. Eric SunshineMay 13, 2013
  31. Johan HerlandMay 13, 2013

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.