summaryrefslogtreecommitdiff
path: root/builtin-remote.c
diff options
context:
space:
mode:
authorJonas Fonseca <fonseca@diku.dk>2008-04-13 09:56:54 (GMT)
committerJunio C Hamano <gitster@pobox.com>2008-04-18 23:31:27 (GMT)
commit24b6177e0261efba063c0b83ae0cdc5993945da9 (patch)
tree668917044c4bb47748f7a39339313591c8487bb0 /builtin-remote.c
parentd0ab520a2599afdfd4d61894863984fc36842b12 (diff)
downloadgit-24b6177e0261efba063c0b83ae0cdc5993945da9.zip
git-24b6177e0261efba063c0b83ae0cdc5993945da9.tar.gz
git-24b6177e0261efba063c0b83ae0cdc5993945da9.tar.bz2
git-remote: reject adding remotes with invalid names
This can happen if the arguments to git-remote add is switched by the user, and git would only show an error if fetching was also requested. Fix it by using the refspec parsing engine to check if the requested name can be parsed as a remote before add it. Also cleanup so that the "remote.<name>.url" config name buffer is only initialized once. Signed-off-by: Jonas Fonseca <fonseca@diku.dk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-remote.c')
-rw-r--r--builtin-remote.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/builtin-remote.c b/builtin-remote.c
index d77f10a..8fe31db 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -88,18 +88,22 @@ static int add(int argc, const char **argv)
strbuf_init(&buf, 0);
strbuf_init(&buf2, 0);
+ strbuf_addf(&buf2, "refs/heads/test:refs/remotes/%s/test", name);
+ if (!valid_fetch_refspec(buf2.buf))
+ die("'%s' is not a valid remote name", name);
+
strbuf_addf(&buf, "remote.%s.url", name);
if (git_config_set(buf.buf, url))
return 1;
+ strbuf_reset(&buf);
+ strbuf_addf(&buf, "remote.%s.fetch", name);
+
if (track.nr == 0)
path_list_append("*", &track);
for (i = 0; i < track.nr; i++) {
struct path_list_item *item = track.items + i;
- strbuf_reset(&buf);
- strbuf_addf(&buf, "remote.%s.fetch", name);
-
strbuf_reset(&buf2);
if (mirror)
strbuf_addf(&buf2, "refs/%s:refs/%s",