diff options
| author | Ben Straub <bs@github.com> | 2014-01-25 08:04:49 -0800 |
|---|---|---|
| committer | Ben Straub <bs@github.com> | 2014-01-30 15:51:00 -0800 |
| commit | 94f263f59be5be74945367b9793c57f297ed4a44 (patch) | |
| tree | 18c713d67936fcb23f86794684757dbf01141f21 /src/clone.c | |
| parent | 8646b0a0689c89d9cad949754885ec542b4d0ce1 (diff) | |
| download | libgit2-94f263f59be5be74945367b9793c57f297ed4a44.tar.gz | |
Add reflog params to set-head calls
Diffstat (limited to 'src/clone.c')
| -rw-r--r-- | src/clone.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/clone.c b/src/clone.c index 2e9d72ab9..2bf2fc509 100644 --- a/src/clone.c +++ b/src/clone.c @@ -152,21 +152,26 @@ static int reference_matches_remote_head( static int update_head_to_new_branch( git_repository *repo, const git_oid *target, - const char *name) + const char *name, + const char *reflog_message) { git_reference *tracking_branch = NULL; int error = create_tracking_branch(&tracking_branch, repo, target, name); if (!error) error = git_repository_set_head( - repo, git_reference_name(tracking_branch)); + repo, git_reference_name(tracking_branch), + NULL, reflog_message); git_reference_free(tracking_branch); return error; } -static int update_head_to_remote(git_repository *repo, git_remote *remote) +static int update_head_to_remote( + git_repository *repo, + git_remote *remote, + const char *reflog_message) { int error = 0; size_t refs_len; @@ -215,7 +220,8 @@ static int update_head_to_remote(git_repository *repo, git_remote *remote) error = update_head_to_new_branch( repo, &head_info.remote_head_oid, - git_buf_cstr(&head_info.branchname)); + git_buf_cstr(&head_info.branchname), + reflog_message); goto cleanup; } @@ -229,10 +235,11 @@ static int update_head_to_remote(git_repository *repo, git_remote *remote) error = update_head_to_new_branch( repo, &head_info.remote_head_oid, - git_buf_cstr(&head_info.branchname)); + git_buf_cstr(&head_info.branchname), + reflog_message); } else { error = git_repository_set_head_detached( - repo, &head_info.remote_head_oid); + repo, &head_info.remote_head_oid, NULL, reflog_message); } cleanup: @@ -244,7 +251,8 @@ cleanup: static int update_head_to_branch( git_repository *repo, const char *remote_name, - const char *branch) + const char *branch, + const char *reflog_message) { int retcode; git_buf remote_branch_name = GIT_BUF_INIT; @@ -259,7 +267,7 @@ static int update_head_to_branch( if ((retcode = git_reference_lookup(&remote_ref, repo, git_buf_cstr(&remote_branch_name))) < 0) goto cleanup; - retcode = update_head_to_new_branch(repo, git_reference_target(remote_ref), branch); + retcode = update_head_to_new_branch(repo, git_reference_target(remote_ref), branch, reflog_message); cleanup: git_reference_free(remote_ref); @@ -323,6 +331,7 @@ int git_clone_into(git_repository *repo, git_remote *remote, const git_checkout_ { int error = 0, old_fetchhead; git_strarray refspecs; + git_buf reflog_message = GIT_BUF_INIT; assert(repo && remote); @@ -340,15 +349,16 @@ int git_clone_into(git_repository *repo, git_remote *remote, const git_checkout_ old_fetchhead = git_remote_update_fetchhead(remote); git_remote_set_update_fetchhead(remote, 0); + git_buf_printf(&reflog_message, "clone: from %s", git_remote_url(remote)); if ((error = git_remote_fetch(remote)) != 0) goto cleanup; if (branch) - error = update_head_to_branch(repo, git_remote_name(remote), branch); + error = update_head_to_branch(repo, git_remote_name(remote), branch, git_buf_cstr(&reflog_message)); /* Point HEAD to the same ref as the remote's head */ else - error = update_head_to_remote(repo, remote); + error = update_head_to_remote(repo, remote, git_buf_cstr(&reflog_message)); if (!error && should_checkout(repo, git_repository_is_bare(repo), co_opts)) error = git_checkout_head(repo, co_opts); @@ -364,6 +374,7 @@ cleanup: } git_strarray_free(&refspecs); + git_buf_free(&reflog_message); return error; } |
