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@xxxxxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html