mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-08 19:51:31 +00:00
Merge pull request #2683 from libgit2/cmn/remote-unify
remote: unify the creation code
This commit is contained in:
commit
4bb8708730
23
src/remote.c
23
src/remote.c
@ -207,34 +207,15 @@ static int ensure_remote_doesnot_exist(git_repository *repo, const char *name)
|
|||||||
int git_remote_create(git_remote **out, git_repository *repo, const char *name, const char *url)
|
int git_remote_create(git_remote **out, git_repository *repo, const char *name, const char *url)
|
||||||
{
|
{
|
||||||
git_buf buf = GIT_BUF_INIT;
|
git_buf buf = GIT_BUF_INIT;
|
||||||
git_remote *remote = NULL;
|
|
||||||
int error;
|
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 (git_buf_printf(&buf, "+refs/heads/*:refs/remotes/%s/*", name) < 0)
|
if (git_buf_printf(&buf, "+refs/heads/*:refs/remotes/%s/*", name) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (create_internal(&remote, repo, name, url, git_buf_cstr(&buf)) < 0)
|
error = git_remote_create_with_fetchspec(out, repo, name, url, git_buf_cstr(&buf));
|
||||||
goto on_error;
|
|
||||||
|
|
||||||
git_buf_free(&buf);
|
git_buf_free(&buf);
|
||||||
|
|
||||||
if (git_remote_save(remote) < 0)
|
return error;
|
||||||
goto on_error;
|
|
||||||
|
|
||||||
*out = remote;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
on_error:
|
|
||||||
git_buf_free(&buf);
|
|
||||||
git_remote_free(remote);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_remote_create_with_fetchspec(git_remote **out, git_repository *repo, const char *name, const char *url, const char *fetch)
|
int git_remote_create_with_fetchspec(git_remote **out, git_repository *repo, const char *name, const char *url, const char *fetch)
|
||||||
|
Loading…
Reference in New Issue
Block a user