diff options
| author | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-05-03 16:08:33 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-05-08 21:36:40 +0200 |
| commit | a209a025c642498f1fa1aecf91ce9e9504d0d419 (patch) | |
| tree | 92d358bd05de3d24ee5276bfdeb8096b8d31a5d7 /src/remote.c | |
| parent | 3df9cc592220b1da73a1d4ac82847c3c6d92a1fa (diff) | |
| download | libgit2-a209a025c642498f1fa1aecf91ce9e9504d0d419.tar.gz | |
remote: add git_remote_add()
Helper function to create a remote with the default settings
Diffstat (limited to 'src/remote.c')
| -rw-r--r-- | src/remote.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/remote.c b/src/remote.c index 6a1390dba..3678d3475 100644 --- a/src/remote.c +++ b/src/remote.c @@ -476,3 +476,28 @@ int git_remote_list(git_strarray *remotes_list, git_repository *repo) return 0; } + +int git_remote_add(git_remote **out, git_repository *repo, const char *name, const char *url) +{ + git_buf buf = GIT_BUF_INIT; + if (git_remote_new(out, repo, url, name) < 0) + return -1; + + if (git_buf_printf(&buf, "refs/heads/*:refs/remotes/%s/*", name) < 0) + goto on_error; + + if (git_remote_set_fetchspec(*out, git_buf_cstr(&buf)) < 0) + goto on_error; + + git_buf_free(&buf); + + if (git_remote_save(*out) < 0) + return -1; + + return 0; + +on_error: + git_buf_free(&buf); + git_remote_free(*out); + return -1; +} |
