aboutsummaryrefslogtreecommitdiff
path: root/remote.c
diff options
context:
space:
mode:
authorJonas Fonseca <fonseca@diku.dk>2008-04-13 11:56:54 +0200
committerJunio C Hamano <gitster@pobox.com>2008-04-18 16:31:27 -0700
commit24b6177e0261efba063c0b83ae0cdc5993945da9 (patch)
tree668917044c4bb47748f7a39339313591c8487bb0 /remote.c
parentd0ab520a2599afdfd4d61894863984fc36842b12 (diff)
downloadgit-24b6177e0261efba063c0b83ae0cdc5993945da9.tar.gz
git-24b6177e0261efba063c0b83ae0cdc5993945da9.tar.xz
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 'remote.c')
-rw-r--r--remote.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/remote.c b/remote.c
index 369dc3398..06ad15627 100644
--- a/remote.c
+++ b/remote.c
@@ -409,7 +409,7 @@ static void read_config(void)
alias_all_urls();
}
-static struct refspec *parse_refspec_internal(int nr_refspec, const char **refspec, int fetch)
+static struct refspec *parse_refspec_internal(int nr_refspec, const char **refspec, int fetch, int verify)
{
int i;
int st;
@@ -519,17 +519,32 @@ static struct refspec *parse_refspec_internal(int nr_refspec, const char **refsp
return rs;
invalid:
+ if (verify) {
+ free(rs);
+ return NULL;
+ }
die("Invalid refspec '%s'", refspec[i]);
}
+int valid_fetch_refspec(const char *fetch_refspec_str)
+{
+ const char *fetch_refspec[] = { fetch_refspec_str };
+ struct refspec *refspec;
+
+ refspec = parse_refspec_internal(1, fetch_refspec, 1, 1);
+ if (refspec)
+ free(refspec);
+ return !!refspec;
+}
+
struct refspec *parse_fetch_refspec(int nr_refspec, const char **refspec)
{
- return parse_refspec_internal(nr_refspec, refspec, 1);
+ return parse_refspec_internal(nr_refspec, refspec, 1, 0);
}
struct refspec *parse_push_refspec(int nr_refspec, const char **refspec)
{
- return parse_refspec_internal(nr_refspec, refspec, 0);
+ return parse_refspec_internal(nr_refspec, refspec, 0, 0);
}
static int valid_remote_nick(const char *name)