Commit 99e40a67 by Edward Thomson Committed by GitHub

Merge pull request #4263 from libgit2/ethomson/config_for_inmemory_repo

Allow creation of a configuration object in an in-memory repository
parents d9914fb7 fe9a5dd3
......@@ -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);
......
......@@ -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);
......@@ -2266,13 +2263,13 @@ 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");
return -1;
giterr_set(GITERR_INVALID, "path cannot exist in repository");
return GIT_ENOTFOUND;
}
if (git_buf_sets(out, parent) < 0)
......
......@@ -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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment