mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-09 15:00:04 +00:00
Add git_remote_set_{fetch,push}spec()
Allow setting the fetch and push refspecs, which is useful for creating new refspecs.
This commit is contained in:
parent
555c81f335
commit
bcb8c007f1
@ -69,6 +69,15 @@ GIT_EXTERN(const char *) git_remote_name(git_remote *remote);
|
||||
*/
|
||||
GIT_EXTERN(const char *) git_remote_url(git_remote *remote);
|
||||
|
||||
/**
|
||||
* Set the remote's fetch refspec
|
||||
*
|
||||
* @param remote the remote
|
||||
* @apram spec the new fetch refspec
|
||||
* @return GIT_SUCCESS or an error value
|
||||
*/
|
||||
GIT_EXTERN(int) git_remote_set_fetchspec(git_remote *remote, const char *spec);
|
||||
|
||||
/**
|
||||
* Get the fetch refspec
|
||||
*
|
||||
@ -77,6 +86,15 @@ GIT_EXTERN(const char *) git_remote_url(git_remote *remote);
|
||||
*/
|
||||
GIT_EXTERN(const git_refspec *) git_remote_fetchspec(git_remote *remote);
|
||||
|
||||
/**
|
||||
* Set the remote's push refspec
|
||||
*
|
||||
* @param remote the remote
|
||||
* @apram spec the new push refspec
|
||||
* @return GIT_SUCCESS or an error value
|
||||
*/
|
||||
GIT_EXTERN(int) git_remote_set_pushspec(git_remote *remote, const char *spec);
|
||||
|
||||
/**
|
||||
* Get the push refspec
|
||||
*
|
||||
|
38
src/remote.c
38
src/remote.c
@ -199,12 +199,50 @@ const char *git_remote_url(git_remote *remote)
|
||||
return remote->url;
|
||||
}
|
||||
|
||||
int git_remote_set_fetchspec(git_remote *remote, const char *spec)
|
||||
{
|
||||
int error;
|
||||
git_refspec refspec;
|
||||
|
||||
assert(remote && spec);
|
||||
|
||||
error = refspec_parse(&refspec, spec);
|
||||
if (error != GIT_SUCCESS)
|
||||
return error;
|
||||
|
||||
git__free(remote->fetch.src);
|
||||
git__free(remote->fetch.dst);
|
||||
remote->fetch.src = refspec.src;
|
||||
remote->fetch.dst = refspec.dst;
|
||||
|
||||
return GIT_SUCCESS;
|
||||
}
|
||||
|
||||
const git_refspec *git_remote_fetchspec(git_remote *remote)
|
||||
{
|
||||
assert(remote);
|
||||
return &remote->fetch;
|
||||
}
|
||||
|
||||
int git_remote_set_pushspec(git_remote *remote, const char *spec)
|
||||
{
|
||||
int error;
|
||||
git_refspec refspec;
|
||||
|
||||
assert(remote && spec);
|
||||
|
||||
error = refspec_parse(&refspec, spec);
|
||||
if (error != GIT_SUCCESS)
|
||||
return error;
|
||||
|
||||
git__free(remote->push.src);
|
||||
git__free(remote->push.dst);
|
||||
remote->push.src = refspec.src;
|
||||
remote->push.dst = refspec.dst;
|
||||
|
||||
return GIT_SUCCESS;
|
||||
}
|
||||
|
||||
const git_refspec *git_remote_pushspec(git_remote *remote)
|
||||
{
|
||||
assert(remote);
|
||||
|
@ -36,6 +36,22 @@ void test_network_remotes__refspec_parsing(void)
|
||||
cl_assert(!strcmp(git_refspec_dst(_refspec), "refs/remotes/test/*"));
|
||||
}
|
||||
|
||||
void test_network_remotes__set_fetchspec(void)
|
||||
{
|
||||
cl_git_pass(git_remote_set_fetchspec(_remote, "refs/*:refs/*"));
|
||||
_refspec = git_remote_fetchspec(_remote);
|
||||
cl_assert(!strcmp(git_refspec_src(_refspec), "refs/*"));
|
||||
cl_assert(!strcmp(git_refspec_dst(_refspec), "refs/*"));
|
||||
}
|
||||
|
||||
void test_network_remotes__set_pushspec(void)
|
||||
{
|
||||
cl_git_pass(git_remote_set_pushspec(_remote, "refs/*:refs/*"));
|
||||
_refspec = git_remote_pushspec(_remote);
|
||||
cl_assert(!strcmp(git_refspec_src(_refspec), "refs/*"));
|
||||
cl_assert(!strcmp(git_refspec_dst(_refspec), "refs/*"));
|
||||
}
|
||||
|
||||
void test_network_remotes__fnmatch(void)
|
||||
{
|
||||
cl_git_pass(git_refspec_src_match(_refspec, "refs/heads/master"));
|
||||
|
Loading…
Reference in New Issue
Block a user