mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-02 14:37:30 +00:00
Merge pull request #4263 from libgit2/ethomson/config_for_inmemory_repo
Allow creation of a configuration object in an in-memory repository
This commit is contained in:
commit
99e40a67c7
@ -433,12 +433,12 @@ typedef enum {
|
|||||||
* item. It will thereby honor things like the repository's
|
* item. It will thereby honor things like the repository's
|
||||||
* common directory, gitdir, etc. In case a file path cannot
|
* common directory, gitdir, etc. In case a file path cannot
|
||||||
* exist for a given item (e.g. the working directory of a bare
|
* 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 out Buffer to store the path at
|
||||||
* @param repo Repository to get path for
|
* @param repo Repository to get path for
|
||||||
* @param item The repository item for which to retrieve the path
|
* @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);
|
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)
|
if ((error = git_config_new(&cfg)) < 0)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
error = git_repository_item_path(&config_path, repo, GIT_REPOSITORY_ITEM_CONFIG);
|
if ((error = git_repository_item_path(&config_path, repo, GIT_REPOSITORY_ITEM_CONFIG)) == 0)
|
||||||
if (error < 0)
|
error = git_config_add_file_ondisk(cfg, config_path.ptr, GIT_CONFIG_LEVEL_LOCAL, 0);
|
||||||
goto on_error;
|
|
||||||
|
|
||||||
if ((error = git_config_add_file_ondisk(
|
if (error && error != GIT_ENOTFOUND)
|
||||||
cfg, config_path.ptr, GIT_CONFIG_LEVEL_LOCAL, 0)) < 0 &&
|
|
||||||
error != GIT_ENOTFOUND)
|
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
|
||||||
git_buf_free(&config_path);
|
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);
|
parent = git_repository_commondir(repo);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
giterr_set(GITERR_INVALID, "Invalid item directory");
|
giterr_set(GITERR_INVALID, "invalid item directory");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent == NULL) {
|
if (parent == NULL) {
|
||||||
giterr_set(GITERR_INVALID, "Path cannot exist in repository");
|
giterr_set(GITERR_INVALID, "path cannot exist in repository");
|
||||||
return -1;
|
return GIT_ENOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (git_buf_sets(out, parent) < 0)
|
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_fixture_cleanup("target.git");
|
||||||
cl_git_sandbox_cleanup();
|
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);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user