From d723dbed0c46ddb2fb037c63cc13a6131c3824b8 Mon Sep 17 00:00:00 2001 From: Arthur Schreiber Date: Fri, 30 May 2014 19:26:49 +0200 Subject: [PATCH] Remote: Set an error when a remote cannot be found. Inside `git_remote_load`, the calls to `get_optional_config` use `giterr_clear` to unset any errors that are set due to missing config keys. If neither a fetch nor a push url config was found for a remote, we should set an error again. --- src/remote.c | 1 + tests/network/remote/remotes.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/remote.c b/src/remote.c index f2e2e2f7a..abcf55e3d 100644 --- a/src/remote.c +++ b/src/remote.c @@ -403,6 +403,7 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name) if (!optional_setting_found) { error = GIT_ENOTFOUND; + giterr_set(GITERR_CONFIG, "Remote '%s' does not exist.", name); goto cleanup; } diff --git a/tests/network/remote/remotes.c b/tests/network/remote/remotes.c index 306ccaee5..333b52a5b 100644 --- a/tests/network/remote/remotes.c +++ b/tests/network/remote/remotes.c @@ -60,6 +60,15 @@ void test_network_remote_remotes__pushurl(void) cl_assert(git_remote_pushurl(_remote) == NULL); } +void test_network_remote_remotes__error_when_not_found(void) +{ + git_remote *r; + cl_git_fail_with(git_remote_load(&r, _repo, "does-not-exist"), GIT_ENOTFOUND); + + cl_assert(giterr_last() != NULL); + cl_assert(giterr_last()->klass == GITERR_CONFIG); +} + void test_network_remote_remotes__error_when_no_push_available(void) { git_remote *r;