mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-11 07:53:55 +00:00
Merge pull request #1951 from victorgp/create-remote-plus-fetch
Allowing create remotes with custom fetch spec
This commit is contained in:
commit
7b947bf5cc
@ -42,6 +42,25 @@ GIT_EXTERN(int) git_remote_create(
|
|||||||
const char *name,
|
const char *name,
|
||||||
const char *url);
|
const char *url);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a remote with the provided fetch refspec (or default if NULL) to the repository's
|
||||||
|
* configuration. This
|
||||||
|
* calls git_remote_save before returning.
|
||||||
|
*
|
||||||
|
* @param out the resulting remote
|
||||||
|
* @param repo the repository in which to create the remote
|
||||||
|
* @param name the remote's name
|
||||||
|
* @param url the remote's url
|
||||||
|
* @param fetch the remote fetch value
|
||||||
|
* @return 0, GIT_EINVALIDSPEC, GIT_EEXISTS or an error code
|
||||||
|
*/
|
||||||
|
GIT_EXTERN(int) git_remote_create_with_fetchspec(
|
||||||
|
git_remote **out,
|
||||||
|
git_repository *repo,
|
||||||
|
const char *name,
|
||||||
|
const char *url,
|
||||||
|
const char *fetch);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a remote in memory
|
* Create a remote in memory
|
||||||
*
|
*
|
||||||
|
30
src/remote.c
30
src/remote.c
@ -209,6 +209,36 @@ on_error:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int git_remote_create_with_fetchspec(git_remote **out, git_repository *repo, const char *name, const char *url, const char *fetch)
|
||||||
|
{
|
||||||
|
git_buf buf = GIT_BUF_INIT;
|
||||||
|
git_remote *remote = NULL;
|
||||||
|
int error;
|
||||||
|
|
||||||
|
if ((error = ensure_remote_name_is_valid(name)) < 0)
|
||||||
|
return error;
|
||||||
|
|
||||||
|
if ((error = ensure_remote_doesnot_exist(repo, name)) < 0)
|
||||||
|
return error;
|
||||||
|
|
||||||
|
if (create_internal(&remote, repo, name, url, fetch) < 0)
|
||||||
|
goto on_error;
|
||||||
|
|
||||||
|
git_buf_free(&buf);
|
||||||
|
|
||||||
|
if (git_remote_save(remote) < 0)
|
||||||
|
goto on_error;
|
||||||
|
|
||||||
|
*out = remote;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
on_error:
|
||||||
|
git_buf_free(&buf);
|
||||||
|
git_remote_free(remote);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int git_remote_create_inmemory(git_remote **out, git_repository *repo, const char *fetch, const char *url)
|
int git_remote_create_inmemory(git_remote **out, git_repository *repo, const char *fetch, const char *url)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
|
@ -450,7 +450,6 @@ void test_network_remote_remotes__cannot_create_a_remote_which_name_conflicts_wi
|
|||||||
assert_cannot_create_remote("test", GIT_EEXISTS);
|
assert_cannot_create_remote("test", GIT_EEXISTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void test_network_remote_remotes__cannot_create_a_remote_which_name_is_invalid(void)
|
void test_network_remote_remotes__cannot_create_a_remote_which_name_is_invalid(void)
|
||||||
{
|
{
|
||||||
assert_cannot_create_remote("/", GIT_EINVALIDSPEC);
|
assert_cannot_create_remote("/", GIT_EINVALIDSPEC);
|
||||||
@ -459,6 +458,17 @@ void test_network_remote_remotes__cannot_create_a_remote_which_name_is_invalid(v
|
|||||||
assert_cannot_create_remote("a.lock", GIT_EINVALIDSPEC);
|
assert_cannot_create_remote("a.lock", GIT_EINVALIDSPEC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_network_remote_remote__git_remote_create_with_fetchspec(void)
|
||||||
|
{
|
||||||
|
git_remote *remote;
|
||||||
|
git_strarray array;
|
||||||
|
|
||||||
|
cl_git_pass(git_remote_create_with_fetchspec(&remote, _repo, "test-new", "git://github.com/libgit2/libgit2", "+refs/*:refs/*"));
|
||||||
|
git_remote_get_fetch_refspecs(&array, remote);
|
||||||
|
cl_assert_equal_s("+refs/*:refs/*", array.strings[0]);
|
||||||
|
git_remote_free(remote);
|
||||||
|
}
|
||||||
|
|
||||||
static const char *fetch_refspecs[] = {
|
static const char *fetch_refspecs[] = {
|
||||||
"+refs/heads/*:refs/remotes/origin/*",
|
"+refs/heads/*:refs/remotes/origin/*",
|
||||||
"refs/tags/*:refs/tags/*",
|
"refs/tags/*:refs/tags/*",
|
||||||
|
Loading…
Reference in New Issue
Block a user