summaryrefslogtreecommitdiff
path: root/src/remote.c
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2012-11-12 12:32:31 +0100
committernulltoken <emeric.fermas@gmail.com>2012-12-01 08:34:23 +0100
commit032ba9e4adf61dd9f33fa4eac03618378b52adb3 (patch)
tree6b24839a471b38144290bf2d3c30e7796d5acd21 /src/remote.c
parent8b50935a69c4e69f9975bad11caeb0ba04adec85 (diff)
downloadlibgit2-032ba9e4adf61dd9f33fa4eac03618378b52adb3.tar.gz
remote: deploy EINVALIDSPEC usage
Diffstat (limited to 'src/remote.c')
-rw-r--r--src/remote.c67
1 files changed, 41 insertions, 26 deletions
diff --git a/src/remote.c b/src/remote.c
index c84911aa1..dc8d9681c 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -57,6 +57,32 @@ static int download_tags_value(git_remote *remote, git_config *cfg)
return error;
}
+static int ensure_remote_name_is_valid(const char *name)
+{
+ git_buf buf = GIT_BUF_INIT;
+ git_refspec refspec;
+ int error = -1;
+
+ if (!name || *name == '\0')
+ goto cleanup;
+
+ git_buf_printf(&buf, "refs/heads/test:refs/remotes/%s/test", name);
+ error = git_refspec__parse(&refspec, git_buf_cstr(&buf), true);
+
+ git_buf_free(&buf);
+ git_refspec__free(&refspec);
+
+cleanup:
+ if (error) {
+ giterr_set(
+ GITERR_CONFIG,
+ "'%s' is not a valid remote name.", name);
+ error = GIT_EINVALIDSPEC;
+ }
+
+ return error;
+}
+
int git_remote_new(git_remote **out, git_repository *repo, const char *name, const char *url, const char *fetch)
{
git_remote *remote;
@@ -79,6 +105,12 @@ int git_remote_new(git_remote **out, git_repository *repo, const char *name, con
GITERR_CHECK_ALLOC(remote->url);
if (name != NULL) {
+ int error;
+ if ((error = ensure_remote_name_is_valid(name)) < 0) {
+ git_remote_free(remote);
+ return error;
+ }
+
remote->name = git__strdup(name);
GITERR_CHECK_ALLOC(remote->name);
}
@@ -111,6 +143,9 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name)
assert(out && repo && name);
+ if ((error = ensure_remote_name_is_valid(name)) < 0)
+ return error;
+
if (git_repository_config__weakptr(&config, repo) < 0)
return -1;
@@ -212,30 +247,6 @@ cleanup:
return error;
}
-static int ensure_remote_name_is_valid(const char *name)
-{
- git_buf buf = GIT_BUF_INIT;
- git_refspec refspec;
- int error = -1;
-
- if (!name || *name == '\0')
- goto cleanup;
-
- git_buf_printf(&buf, "refs/heads/test:refs/remotes/%s/test", name);
- error = git_refspec__parse(&refspec, git_buf_cstr(&buf), true);
-
- git_buf_free(&buf);
- git_refspec__free(&refspec);
-
-cleanup:
- if (error)
- giterr_set(
- GITERR_CONFIG,
- "'%s' is not a valid remote name.", name);
-
- return error;
-}
-
static int update_config_refspec(
git_config *config,
const char *remote_name,
@@ -279,8 +290,8 @@ int git_remote_save(const git_remote *remote)
assert(remote);
- if (ensure_remote_name_is_valid(remote->name) < 0)
- return -1;
+ if ((error = ensure_remote_name_is_valid(remote->name)) < 0)
+ return error;
if (git_repository_config__weakptr(&config, remote->repo) < 0)
return -1;
@@ -958,6 +969,10 @@ int git_remote_list(git_strarray *remotes_list, git_repository *repo)
int git_remote_add(git_remote **out, git_repository *repo, const char *name, const char *url)
{
git_buf buf = GIT_BUF_INIT;
+ int error;
+
+ if ((error = ensure_remote_name_is_valid(name)) < 0)
+ return error;
if (git_buf_printf(&buf, "+refs/heads/*:refs/remotes/%s/*", name) < 0)
return -1;