From fb3fc837c6e35075a7060d5702cf122f998d3aea Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 12 Jun 2017 11:45:09 +0100 Subject: [PATCH 1/4] repository_item_path: error messages lowercased --- src/repository.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/repository.c b/src/repository.c index c7b40fdf7..9729d3197 100644 --- a/src/repository.c +++ b/src/repository.c @@ -2266,12 +2266,12 @@ int git_repository_item_path(git_buf *out, git_repository *repo, git_repository_ parent = git_repository_commondir(repo); break; default: - giterr_set(GITERR_INVALID, "Invalid item directory"); + giterr_set(GITERR_INVALID, "invalid item directory"); return -1; } if (parent == NULL) { - giterr_set(GITERR_INVALID, "Path cannot exist in repository"); + giterr_set(GITERR_INVALID, "path cannot exist in repository"); return -1; } From 9d49a43c718d0749231ac54adf4b72775cc40354 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 12 Jun 2017 12:01:10 +0100 Subject: [PATCH 2/4] repository_item_path: return ENOTFOUND when appropriate Disambiguate error values: return `GIT_ENOTFOUND` when the item cannot exist in the repository (perhaps because the repository is inmemory or otherwise not backed by a filesystem), return `-1` when there is a hard failure. --- include/git2/repository.h | 4 ++-- src/repository.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/git2/repository.h b/include/git2/repository.h index a396a5409..8aac0b3f7 100644 --- a/include/git2/repository.h +++ b/include/git2/repository.h @@ -433,12 +433,12 @@ typedef enum { * item. It will thereby honor things like the repository's * common directory, gitdir, etc. In case a file path cannot * exist for a given item (e.g. the working directory of a bare - * repository), an error is returned. + * repository), GIT_ENOTFOUND is returned. * * @param out Buffer to store the path at * @param repo Repository to get path for * @param item The repository item for which to retrieve the path - * @return 0 on success, otherwise a negative value + * @return 0, GIT_ENOTFOUND if the path cannot exist or an error code */ GIT_EXTERN(int) git_repository_item_path(git_buf *out, git_repository *repo, git_repository_item_t item); diff --git a/src/repository.c b/src/repository.c index 9729d3197..27553ad0a 100644 --- a/src/repository.c +++ b/src/repository.c @@ -2272,7 +2272,7 @@ int git_repository_item_path(git_buf *out, git_repository *repo, git_repository_ if (parent == NULL) { giterr_set(GITERR_INVALID, "path cannot exist in repository"); - return -1; + return GIT_ENOTFOUND; } if (git_buf_sets(out, parent) < 0) From 2d486781df0828eae716937b23d2df0a9c1817f9 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 12 Jun 2017 12:02:27 +0100 Subject: [PATCH 3/4] repository: don't fail to create config option in inmemory repo When in an in-memory repository - without a configuration file - do not fail to create a configuration object. --- src/repository.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/repository.c b/src/repository.c index 27553ad0a..7ecb00ed8 100644 --- a/src/repository.c +++ b/src/repository.c @@ -943,13 +943,10 @@ static int load_config( if ((error = git_config_new(&cfg)) < 0) return error; - error = git_repository_item_path(&config_path, repo, GIT_REPOSITORY_ITEM_CONFIG); - if (error < 0) - goto on_error; + if ((error = git_repository_item_path(&config_path, repo, GIT_REPOSITORY_ITEM_CONFIG)) == 0) + error = git_config_add_file_ondisk(cfg, config_path.ptr, GIT_CONFIG_LEVEL_LOCAL, 0); - if ((error = git_config_add_file_ondisk( - cfg, config_path.ptr, GIT_CONFIG_LEVEL_LOCAL, 0)) < 0 && - error != GIT_ENOTFOUND) + if (error && error != GIT_ENOTFOUND) goto on_error; git_buf_free(&config_path); From fe9a5dd3cab5e5137603503bb461b6a52793d56f Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 12 Jun 2017 12:00:14 +0100 Subject: [PATCH 4/4] remote: ensure we can create an anon remote on inmemory repo Given a wholly in-memory repository, ensure that we can create an anonymous remote and perform actions on it. --- tests/network/remote/local.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/network/remote/local.c b/tests/network/remote/local.c index 6194802af..7bae03847 100644 --- a/tests/network/remote/local.c +++ b/tests/network/remote/local.c @@ -465,3 +465,19 @@ void test_network_remote_local__push_delete(void) cl_fixture_cleanup("target.git"); cl_git_sandbox_cleanup(); } + +void test_network_remote_local__anonymous_remote_inmemory_repo(void) +{ + git_repository *inmemory; + git_remote *remote; + + git_buf_sets(&file_path_buf, cl_git_path_url(cl_fixture("testrepo.git"))); + + cl_git_pass(git_repository_new(&inmemory)); + cl_git_pass(git_remote_create_anonymous(&remote, inmemory, git_buf_cstr(&file_path_buf))); + cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL, NULL)); + cl_assert(git_remote_connected(remote)); + git_remote_disconnect(remote); + git_remote_free(remote); + git_repository_free(inmemory); +}