summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/clone.c31
-rw-r--r--src/refs.c2
-rw-r--r--src/repository.c27
3 files changed, 40 insertions, 20 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;
}
diff --git a/src/refs.c b/src/refs.c
index 0f0a380ea..65e7e6439 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -545,7 +545,7 @@ static int reference__rename(git_reference **out, git_reference *ref, const char
/* Update HEAD it was pointing to the reference being renamed */
if (should_head_be_updated &&
- (error = git_repository_set_head(ref->db->repo, new_name)) < 0) {
+ (error = git_repository_set_head(ref->db->repo, new_name, signature, message)) < 0) {
giterr_set(GITERR_REFERENCE, "Failed to update HEAD after renaming reference");
return error;
}
diff --git a/src/repository.c b/src/repository.c
index 285d8897f..2c1b60266 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -1830,7 +1830,9 @@ static bool looks_like_a_branch(const char *refname)
int git_repository_set_head(
git_repository* repo,
- const char* refname)
+ const char* refname,
+ const git_signature *signature,
+ const char *log_message)
{
git_reference *ref,
*new_head = NULL;
@@ -1843,12 +1845,17 @@ int git_repository_set_head(
return error;
if (!error) {
- if (git_reference_is_branch(ref))
- error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, git_reference_name(ref), 1, NULL, NULL);
- else
- error = git_repository_set_head_detached(repo, git_reference_target(ref));
- } else if (looks_like_a_branch(refname))
- error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, refname, 1, NULL, NULL);
+ if (git_reference_is_branch(ref)) {
+ error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE,
+ git_reference_name(ref), true, signature, log_message);
+ } else {
+ error = git_repository_set_head_detached(repo, git_reference_target(ref),
+ signature, log_message);
+ }
+ } else if (looks_like_a_branch(refname)) {
+ error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, refname,
+ true, signature, log_message);
+ }
git_reference_free(ref);
git_reference_free(new_head);
@@ -1857,7 +1864,9 @@ int git_repository_set_head(
int git_repository_set_head_detached(
git_repository* repo,
- const git_oid* commitish)
+ const git_oid* commitish,
+ const git_signature *signature,
+ const char *log_message)
{
int error;
git_object *object,
@@ -1872,7 +1881,7 @@ int git_repository_set_head_detached(
if ((error = git_object_peel(&peeled, object, GIT_OBJ_COMMIT)) < 0)
goto cleanup;
- error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), 1, NULL, NULL);
+ error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), true, signature, log_message);
cleanup:
git_object_free(object);