From b83c92dd6fe11adae0ff29e1db381c31f0f88cb7 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Wed, 21 Aug 2013 13:16:17 +0200 Subject: remote: Assert proper GIT_DIRECTION_XXXX values --- src/remote.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/remote.c') diff --git a/src/remote.c b/src/remote.c index 7677e56b2..14ed740a8 100644 --- a/src/remote.c +++ b/src/remote.c @@ -534,6 +534,8 @@ const char* git_remote__urlfordirection(git_remote *remote, int direction) { assert(remote); + assert(direction == GIT_DIRECTION_FETCH || direction == GIT_DIRECTION_PUSH); + if (direction == GIT_DIRECTION_FETCH) { return remote->url; } -- cgit v1.2.1 From 44bc0c6ac3b939d3dfc1102be77e82e00e919ae4 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Wed, 21 Aug 2013 13:20:17 +0200 Subject: remote: Warn the user when connecting with no url --- src/remote.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/remote.c') diff --git a/src/remote.c b/src/remote.c index 14ed740a8..948c755bb 100644 --- a/src/remote.c +++ b/src/remote.c @@ -558,8 +558,11 @@ int git_remote_connect(git_remote *remote, git_direction direction) t = remote->transport; url = git_remote__urlfordirection(remote, direction); - if (url == NULL ) + if (url == NULL ) { + giterr_set(GITERR_INVALID, + "Malformed remote '%s' - missing URL", remote->name); return -1; + } /* A transport could have been supplied in advance with * git_remote_set_transport */ -- cgit v1.2.1 From ece24ef7c4bb31eb2c715948bcf6dff6ed9d7dfc Mon Sep 17 00:00:00 2001 From: nulltoken Date: Wed, 21 Aug 2013 13:37:21 +0200 Subject: remote: Don't parse missing urls as empty strings --- src/remote.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/remote.c') diff --git a/src/remote.c b/src/remote.c index 948c755bb..4bba1d57e 100644 --- a/src/remote.c +++ b/src/remote.c @@ -308,7 +308,7 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name) if ((error = get_optional_config(config, &buf, NULL, (void *)&val)) < 0) goto cleanup; - if (val) { + if (val && strlen(val) > 0) { remote->pushurl = git__strdup(val); GITERR_CHECK_ALLOC(remote->pushurl); } -- cgit v1.2.1 From c9ffa84bde45021c40623553822916fb3d13b20a Mon Sep 17 00:00:00 2001 From: nulltoken Date: Wed, 21 Aug 2013 16:04:25 +0200 Subject: remote: Relax the parsing logic even more In order to be loaded, a remote needs to be configured with at least a `url` or a `pushurl`. ENOTFOUND will be returned when trying to git_remote_load() a remote with neither of these entries defined. --- src/remote.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'src/remote.c') diff --git a/src/remote.c b/src/remote.c index 4bba1d57e..7276daa39 100644 --- a/src/remote.c +++ b/src/remote.c @@ -233,7 +233,8 @@ static int refspec_cb(const git_config_entry *entry, void *payload) } static int get_optional_config( - git_config *config, git_buf *buf, git_config_foreach_cb cb, void *payload) + bool *found, git_config *config, git_buf *buf, + git_config_foreach_cb cb, void *payload) { int error = 0; const char *key = git_buf_cstr(buf); @@ -246,6 +247,9 @@ static int get_optional_config( else error = git_config_get_string(payload, config, key); + if (found) + *found = !error; + if (error == GIT_ENOTFOUND) { giterr_clear(); error = 0; @@ -265,6 +269,7 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name) int error = 0; git_config *config; struct refspec_cb_data data; + bool optional_setting_found = false, found; assert(out && repo && name); @@ -294,21 +299,33 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name) goto cleanup; } - if ((error = git_config_get_string(&val, config, git_buf_cstr(&buf))) < 0) + if ((error = get_optional_config(&found, config, &buf, NULL, (void *)&val)) < 0) goto cleanup; + optional_setting_found |= found; + remote->repo = repo; - remote->url = git__strdup(val); - GITERR_CHECK_ALLOC(remote->url); + + if (found && strlen(val) > 0) { + remote->url = git__strdup(val); + GITERR_CHECK_ALLOC(remote->url); + } val = NULL; git_buf_clear(&buf); git_buf_printf(&buf, "remote.%s.pushurl", name); - if ((error = get_optional_config(config, &buf, NULL, (void *)&val)) < 0) + if ((error = get_optional_config(&found, config, &buf, NULL, (void *)&val)) < 0) goto cleanup; - if (val && strlen(val) > 0) { + optional_setting_found |= found; + + if (!optional_setting_found) { + error = GIT_ENOTFOUND; + goto cleanup; + } + + if (found && strlen(val) > 0) { remote->pushurl = git__strdup(val); GITERR_CHECK_ALLOC(remote->pushurl); } @@ -318,14 +335,14 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name) git_buf_clear(&buf); git_buf_printf(&buf, "remote.%s.fetch", name); - if ((error = get_optional_config(config, &buf, refspec_cb, &data)) < 0) + if ((error = get_optional_config(NULL, config, &buf, refspec_cb, &data)) < 0) goto cleanup; data.fetch = false; git_buf_clear(&buf); git_buf_printf(&buf, "remote.%s.push", name); - if ((error = get_optional_config(config, &buf, refspec_cb, &data)) < 0) + if ((error = get_optional_config(NULL, config, &buf, refspec_cb, &data)) < 0) goto cleanup; if (download_tags_value(remote, config) < 0) -- cgit v1.2.1 From aec87f712fd1e84038d5d14b83a97d78e2e1b1ad Mon Sep 17 00:00:00 2001 From: nulltoken Date: Tue, 27 Aug 2013 19:14:18 +0200 Subject: remote: Make git_remote_list() detect pushurl --- src/remote.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/remote.c') diff --git a/src/remote.c b/src/remote.c index 7276daa39..10c1b5b81 100644 --- a/src/remote.c +++ b/src/remote.c @@ -1109,10 +1109,10 @@ int git_remote_list(git_strarray *remotes_list, git_repository *repo) if (git_repository_config__weakptr(&cfg, repo) < 0) return -1; - if (git_vector_init(&list, 4, NULL) < 0) + if (git_vector_init(&list, 4, git__strcmp_cb) < 0) return -1; - if (regcomp(&preg, "^remote\\.(.*)\\.url$", REG_EXTENDED) < 0) { + if (regcomp(&preg, "^remote\\.(.*)\\.(push)?url$", REG_EXTENDED) < 0) { giterr_set(GITERR_OS, "Remote catch regex failed to compile"); return -1; } @@ -1137,6 +1137,8 @@ int git_remote_list(git_strarray *remotes_list, git_repository *repo) return error; } + git_vector_uniq(&list, git__free); + remotes_list->strings = (char **)list.contents; remotes_list->count = list.length; -- cgit v1.2.1