diff options
author | Sean Barag <sean@barag.org> | 2020-10-01 03:46:13 +0000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-09-30 22:09:13 -0700 |
commit | f2c6fda88624370fda1fc706a0f2ceda7d50d6ab (patch) | |
tree | 76a1421ef4a334d6bed9dd455ee1d627bb4c3f2e /builtin | |
parent | remote: add tests for add and rename with invalid names (diff) | |
download | tgif-f2c6fda88624370fda1fc706a0f2ceda7d50d6ab.tar.xz |
refs: consolidate remote name validation
In preparation for a future patch, extract from remote.c a function that
validates possible remote names so that its rules can be used
consistently in other places.
Helped-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Sean Barag <sean@barag.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/remote.c | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/builtin/remote.c b/builtin/remote.c index 542f56e387..b2e0959746 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -194,8 +194,7 @@ static int add(int argc, const char **argv) if (remote_is_configured(remote, 1)) 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_remote_name(name)) die(_("'%s' is not a valid remote name"), name); strbuf_addf(&buf, "remote.%s.url", name); @@ -696,11 +695,9 @@ static int mv(int argc, const char **argv) if (remote_is_configured(newremote, 1)) die(_("remote %s already exists."), rename.new_name); - strbuf_addf(&buf, "refs/heads/test:refs/remotes/%s/test", rename.new_name); - if (!valid_fetch_refspec(buf.buf)) + if (!valid_remote_name(rename.new_name)) die(_("'%s' is not a valid remote name"), rename.new_name); - strbuf_reset(&buf); strbuf_addf(&buf, "remote.%s", rename.old_name); strbuf_addf(&buf2, "remote.%s", rename.new_name); if (git_config_rename_section(buf.buf, buf2.buf) < 1) |