summaryrefslogtreecommitdiff
path: root/app/services
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2015-05-05 23:49:30 -0700
committerStan Hu <stanhu@gmail.com>2015-05-05 23:49:30 -0700
commit03138a3c72d9ccdfda6398564c6183de70c68df5 (patch)
treee0730100c63527b5a00b2afc1a6b9ce964ea8014 /app/services
parent91846578711c7f32fd5e26437b5c14c66f8156fb (diff)
downloadgitlab-ce-03138a3c72d9ccdfda6398564c6183de70c68df5.tar.gz
Make the first branch pushed to an empty repository the default HEAD.
In an empty repository, pushing a new branch not called "master" would leave HEAD in an unknown state, causing ambiguity if another branch were pushed. This could in turn cause a new protected branch to be created and cause the default branch to change. * Closes #1561 * Closes #1576 * Closes https://github.com/gitlabhq/gitlabhq/issues/8883
Diffstat (limited to 'app/services')
-rw-r--r--app/services/git_push_service.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb
index 1b889e0da8b..bdf36af02fd 100644
--- a/app/services/git_push_service.rb
+++ b/app/services/git_push_service.rb
@@ -31,6 +31,10 @@ class GitPushService
# Initial push to the default branch. Take the full history of that branch as "newly pushed".
@push_commits = project.repository.commits(newrev)
+ # Ensure HEAD points to the default branch in case it is not master
+ branch_name = Gitlab::Git.ref_name(ref)
+ project.change_head(branch_name)
+
# Set protection on the default branch if configured
if (current_application_settings.default_branch_protection != PROTECTION_NONE)
developers_can_push = current_application_settings.default_branch_protection == PROTECTION_DEV_CAN_PUSH ? true : false