summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-01-07 14:47:02 +0000
committerCarlos Martín Nieto <cmn@dwim.me>2015-03-03 14:40:50 +0100
commit6bfb990dc74c3749b356f82f7c9744b43fe90ea9 (patch)
tree7b9acea4318400e209ce25ffed64df2e5b8ee654 /src
parent23a17803b6e3a8bf21f740726ec0a038968da9a1 (diff)
downloadlibgit2-6bfb990dc74c3749b356f82f7c9744b43fe90ea9.tar.gz
branch: don't accept a reflog message override
This namespace is about behaving like git's branch command, so let's do exactly that instead of taking a reflog message. This override is still available via the reference namespace.
Diffstat (limited to 'src')
-rw-r--r--src/branch.c29
-rw-r--r--src/clone.c6
2 files changed, 16 insertions, 19 deletions
diff --git a/src/branch.c b/src/branch.c
index 762a26211..4e9460f36 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -54,13 +54,12 @@ int git_branch_create(
git_repository *repository,
const char *branch_name,
const git_commit *commit,
- int force,
- const char *log_message)
+ int force)
{
int is_head = 0;
git_reference *branch = NULL;
git_buf canonical_branch_name = GIT_BUF_INIT,
- log_message_buf = GIT_BUF_INIT;
+ log_message = GIT_BUF_INIT;
int error = -1;
assert(branch_name && commit && ref_out);
@@ -87,19 +86,19 @@ int git_branch_create(
if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0)
goto cleanup;
- if (git_buf_sets(&log_message_buf, log_message ? log_message : "Branch: created") < 0)
+ if (git_buf_printf(&log_message, "Branch: created from %s", git_oid_tostr_s(git_commit_id(commit))) < 0)
goto cleanup;
error = git_reference_create(&branch, repository,
git_buf_cstr(&canonical_branch_name), git_commit_id(commit), force,
- git_buf_cstr(&log_message_buf));
+ git_buf_cstr(&log_message));
if (!error)
*ref_out = branch;
cleanup:
git_buf_free(&canonical_branch_name);
- git_buf_free(&log_message_buf);
+ git_buf_free(&log_message);
return error;
}
@@ -221,13 +220,12 @@ int git_branch_move(
git_reference **out,
git_reference *branch,
const char *new_branch_name,
- int force,
- const char *log_message)
+ int force)
{
git_buf new_reference_name = GIT_BUF_INIT,
old_config_section = GIT_BUF_INIT,
new_config_section = GIT_BUF_INIT,
- log_message_buf = GIT_BUF_INIT;
+ log_message = GIT_BUF_INIT;
int error;
assert(branch && new_branch_name);
@@ -238,20 +236,15 @@ int git_branch_move(
if ((error = git_buf_joinpath(&new_reference_name, GIT_REFS_HEADS_DIR, new_branch_name)) < 0)
goto done;
- if (log_message) {
- if ((error = git_buf_sets(&log_message_buf, log_message)) < 0)
+ if ((error = git_buf_printf(&log_message, "Branch: renamed %s to %s",
+ git_reference_name(branch), git_buf_cstr(&new_reference_name))) < 0)
goto done;
- } else {
- if ((error = git_buf_printf(&log_message_buf, "Branch: renamed %s to %s",
- git_reference_name(branch), git_buf_cstr(&new_reference_name))) < 0)
- goto done;
- }
/* first update ref then config so failure won't trash config */
error = git_reference_rename(
out, branch, git_buf_cstr(&new_reference_name), force,
- git_buf_cstr(&log_message_buf));
+ git_buf_cstr(&log_message));
if (error < 0)
goto done;
@@ -268,7 +261,7 @@ done:
git_buf_free(&new_reference_name);
git_buf_free(&old_config_section);
git_buf_free(&new_config_section);
- git_buf_free(&log_message_buf);
+ git_buf_free(&log_message);
return error;
}
diff --git a/src/clone.c b/src/clone.c
index f7ae17c57..ac6a059dd 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -35,6 +35,7 @@ static int create_branch(
{
git_commit *head_obj = NULL;
git_reference *branch_ref = NULL;
+ git_buf refname = GIT_BUF_INIT;
int error;
/* Find the target commit */
@@ -42,8 +43,11 @@ static int create_branch(
return error;
/* Create the new branch */
- error = git_branch_create(&branch_ref, repo, name, head_obj, 0, log_message);
+ if ((error = git_buf_printf(&refname, GIT_REFS_HEADS_DIR "%s", name)) < 0)
+ return error;
+ error = git_reference_create(&branch_ref, repo, git_buf_cstr(&refname), target, 0, log_message);
+ git_buf_free(&refname);
git_commit_free(head_obj);
if (!error)