summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Straub <bs@github.com>2014-03-02 09:00:00 -0600
committerBen Straub <bs@github.com>2014-03-02 09:00:00 -0600
commit494be429ad2d247a8d1fb2b43b8c715a4b9da663 (patch)
treecbff6caa418104eb50118f47a110e64ee5e438fe /src
parent9776cb84fa1cf774447e069e263935e45589b02c (diff)
parent1d08b72e4fbc474719baec127d7911cc116dec48 (diff)
downloadlibgit2-494be429ad2d247a8d1fb2b43b8c715a4b9da663.tar.gz
Merge pull request #2144 from linquize/branch-f-current
Do not allow git_branch_create() to force update branch
Diffstat (limited to 'src')
-rw-r--r--src/branch.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/branch.c b/src/branch.c
index 133d6f6d4..1ebaf8e24 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -58,6 +58,7 @@ int git_branch_create(
const git_signature *signature,
const char *log_message)
{
+ int is_head = 0;
git_reference *branch = NULL;
git_buf canonical_branch_name = GIT_BUF_INIT,
log_message_buf = GIT_BUF_INIT;
@@ -65,7 +66,19 @@ int git_branch_create(
assert(branch_name && commit && ref_out);
assert(git_object_owner((const git_object *)commit) == repository);
+ if (git_branch_lookup(&branch, repository, branch_name, GIT_BRANCH_LOCAL) == 0) {
+ if ((is_head = git_branch_is_head(branch)) < 0) {
+ error = is_head;
+ goto cleanup;
+ }
+ }
+ if (is_head && force) {
+ giterr_set(GITERR_REFERENCE, "Cannot force update branch '%s' as it is "
+ "the current HEAD of the repository.", git_reference_name(branch));
+ goto cleanup;
+ }
+
if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0)
goto cleanup;