summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2016-11-04 18:14:00 +0100
committerPatrick Steinhardt <ps@pks.im>2016-11-04 18:14:00 +0100
commit6e2fab9eded4c815d52ff812671fd7a601ef19d6 (patch)
treec7d9c34958f7976900764daa0855195359827218 /src
parent7175222ce63ef61749cc00a1f29d11d098bd28a8 (diff)
parentf9793884a3fc895a17a2a70709d32cbc2214377b (diff)
downloadlibgit2-6e2fab9eded4c815d52ff812671fd7a601ef19d6.tar.gz
Merge pull request #3977 from jfultz/fix-forced-branch-creation-on-bare-repo
Diffstat (limited to 'src')
-rw-r--r--src/branch.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/branch.c b/src/branch.c
index 51c35d7ff..8d1ed6577 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -58,16 +58,17 @@ static int create_branch(
const char *from,
int force)
{
- int is_head = 0;
+ int is_unmovable_head = 0;
git_reference *branch = NULL;
git_buf canonical_branch_name = GIT_BUF_INIT,
log_message = GIT_BUF_INIT;
int error = -1;
+ int bare = git_repository_is_bare(repository);
assert(branch_name && commit && ref_out);
assert(git_object_owner((const git_object *)commit) == repository);
- if (force && git_branch_lookup(&branch, repository, branch_name, GIT_BRANCH_LOCAL) == 0) {
+ if (force && !bare && git_branch_lookup(&branch, repository, branch_name, GIT_BRANCH_LOCAL) == 0) {
error = git_branch_is_head(branch);
git_reference_free(branch);
branch = NULL;
@@ -75,10 +76,10 @@ static int create_branch(
if (error < 0)
goto cleanup;
- is_head = error;
+ is_unmovable_head = error;
}
- if (is_head && force) {
+ if (is_unmovable_head && force) {
giterr_set(GITERR_REFERENCE, "Cannot force update branch '%s' as it is "
"the current HEAD of the repository.", branch_name);
error = -1;