diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/clone.c | 23 | ||||
| -rw-r--r-- | src/remote.c | 20 |
2 files changed, 26 insertions, 17 deletions
diff --git a/src/clone.c b/src/clone.c index 7d49b398b..55638fd05 100644 --- a/src/clone.c +++ b/src/clone.c @@ -262,15 +262,14 @@ cleanup: static int setup_remotes_and_fetch( git_repository *repo, - const char *origin_url, + git_remote *origin, git_transfer_progress_callback progress_cb, void *progress_payload) { int retcode = GIT_ERROR; - git_remote *origin = NULL; - /* Create the "origin" remote */ - if (!git_remote_add(&origin, repo, GIT_REMOTE_ORIGIN, origin_url)) { + /* Add the origin remote */ + if (!git_remote_set_repository(origin, repo) && !git_remote_save(origin)) { /* * Don't write FETCH_HEAD, we'll check out the remote tracking * branch ourselves based on the server's default. @@ -325,7 +324,7 @@ static bool should_checkout( static int clone_internal( git_repository **out, - const char *origin_url, + git_remote *origin_remote, const char *path, git_transfer_progress_callback fetch_progress_cb, void *fetch_progress_payload, @@ -340,7 +339,7 @@ static int clone_internal( } if (!(retcode = git_repository_init(&repo, path, is_bare))) { - if ((retcode = setup_remotes_and_fetch(repo, origin_url, + if ((retcode = setup_remotes_and_fetch(repo, origin_remote, fetch_progress_cb, fetch_progress_payload)) < 0) { /* Failed to fetch; clean up */ git_repository_free(repo); @@ -359,16 +358,16 @@ static int clone_internal( int git_clone_bare( git_repository **out, - const char *origin_url, + git_remote *origin_remote, const char *dest_path, git_transfer_progress_callback fetch_progress_cb, void *fetch_progress_payload) { - assert(out && origin_url && dest_path); + assert(out && origin_remote && dest_path); return clone_internal( out, - origin_url, + origin_remote, dest_path, fetch_progress_cb, fetch_progress_payload, @@ -379,17 +378,17 @@ int git_clone_bare( int git_clone( git_repository **out, - const char *origin_url, + git_remote *origin_remote, const char *workdir_path, git_checkout_opts *checkout_opts, git_transfer_progress_callback fetch_progress_cb, void *fetch_progress_payload) { - assert(out && origin_url && workdir_path); + assert(out && origin_remote && workdir_path); return clone_internal( out, - origin_url, + origin_remote, workdir_path, fetch_progress_cb, fetch_progress_payload, diff --git a/src/remote.c b/src/remote.c index f430cd03a..24a821e44 100644 --- a/src/remote.c +++ b/src/remote.c @@ -86,6 +86,8 @@ cleanup: int git_remote_new(git_remote **out, git_repository *repo, const char *name, const char *url, const char *fetch) { git_remote *remote; + git_buf fetchbuf = GIT_BUF_INIT; + int error = -1; /* name is optional */ assert(out && url); @@ -98,20 +100,26 @@ int git_remote_new(git_remote **out, git_repository *repo, const char *name, con remote->update_fetchhead = 1; if (git_vector_init(&remote->refs, 32, NULL) < 0) - return -1; + goto on_error; remote->url = git__strdup(url); GITERR_CHECK_ALLOC(remote->url); if (name != NULL) { - int error; if ((error = ensure_remote_name_is_valid(name)) < 0) { - git_remote_free(remote); - return error; + error = GIT_EINVALIDSPEC; + goto on_error; } remote->name = git__strdup(name); GITERR_CHECK_ALLOC(remote->name); + + /* An empty name indicates to use a sensible default for the fetchspec. */ + if (fetch && strlen(fetch) == 0) { + if (git_buf_printf(&fetchbuf, "+refs/heads/*:refs/remotes/%s/*", remote->name) < 0) + goto on_error; + fetch = git_buf_cstr(&fetchbuf); + } } if (fetch != NULL) { @@ -125,11 +133,13 @@ int git_remote_new(git_remote **out, git_repository *repo, const char *name, con } *out = remote; + git_buf_free(&fetchbuf); return 0; on_error: git_remote_free(remote); - return -1; + git_buf_free(&fetchbuf); + return error; } int git_remote_set_repository(git_remote *remote, git_repository *repo) |
