mirror of
https://git.proxmox.com/git/libgit2
synced 2026-01-06 00:13:01 +00:00
Make sure git_remote_dup copies a remote's refspecs correctly.
This commit is contained in:
parent
11f6ad5fcf
commit
991b2840eb
@ -117,7 +117,7 @@ GIT_EXTERN(int) git_remote_save(const git_remote *remote);
|
||||
* @param source object to copy
|
||||
* @return 0 or an error code
|
||||
*/
|
||||
GIT_EXTERN(int) git_remote_dup(git_remote **dest, const git_remote *source);
|
||||
GIT_EXTERN(int) git_remote_dup(git_remote **dest, git_remote *source);
|
||||
|
||||
/**
|
||||
* Get the remote's repository
|
||||
|
||||
34
src/remote.c
34
src/remote.c
@ -248,9 +248,10 @@ int git_remote_create_inmemory(git_remote **out, git_repository *repo, const cha
|
||||
return 0;
|
||||
}
|
||||
|
||||
int git_remote_dup(git_remote **dest, const git_remote *source)
|
||||
int git_remote_dup(git_remote **dest, git_remote *source)
|
||||
{
|
||||
int error;
|
||||
int error = 0;
|
||||
git_strarray refspecs = { 0 };
|
||||
git_remote *remote = git__calloc(1, sizeof(git_remote));
|
||||
GITERR_CHECK_ALLOC(remote);
|
||||
|
||||
@ -274,16 +275,33 @@ int git_remote_dup(git_remote **dest, const git_remote *source)
|
||||
remote->check_cert = source->check_cert;
|
||||
remote->update_fetchhead = source->update_fetchhead;
|
||||
|
||||
if ((error = git_vector_dup(&remote->refs, &source->refs, NULL)) < 0 ||
|
||||
(error = git_vector_dup(&remote->refspecs, &source->refspecs, NULL)) < 0 ||
|
||||
(error = git_vector_dup(&remote->active_refspecs, &source->active_refspecs, NULL))) {
|
||||
git__free(remote);
|
||||
return error;
|
||||
if (git_vector_init(&remote->refs, 32, NULL) < 0 ||
|
||||
git_vector_init(&remote->refspecs, 2, NULL) < 0 ||
|
||||
git_vector_init(&remote->active_refspecs, 2, NULL) < 0) {
|
||||
error = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((error = git_remote_get_fetch_refspecs(&refspecs, source)) < 0 ||
|
||||
(error = git_remote_set_fetch_refspecs(remote, &refspecs)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
git_strarray_free(&refspecs);
|
||||
|
||||
if ((error = git_remote_get_push_refspecs(&refspecs, source)) < 0 ||
|
||||
(error = git_remote_set_push_refspecs(remote, &refspecs)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
*dest = remote;
|
||||
|
||||
return 0;
|
||||
cleanup:
|
||||
|
||||
git_strarray_free(&refspecs);
|
||||
|
||||
if (error < 0)
|
||||
git__free(remote);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
struct refspec_cb_data {
|
||||
|
||||
@ -148,6 +148,8 @@ void test_network_remote_remotes__dup(void)
|
||||
cl_git_pass(git_remote_get_push_refspecs(&array, _remote));
|
||||
cl_assert_equal_i(0, (int)array.count);
|
||||
git_strarray_free(&array);
|
||||
|
||||
git_remote_free(dup);
|
||||
}
|
||||
|
||||
void test_network_remote_remotes__add_pushspec(void)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user