diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-05-07 10:28:50 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-05-07 10:28:50 +0000 |
commit | 7a23be3ab7c8b3911a35686516ac7fe3f43c81a6 (patch) | |
tree | 79b2fc7546ff140c54f62863a238a9eb4dddd56f | |
parent | 60887cf94904e10cd26246301d09a49be49ef5fa (diff) | |
parent | 03138a3c72d9ccdfda6398564c6183de70c68df5 (diff) | |
download | gitlab-ce-7a23be3ab7c8b3911a35686516ac7fe3f43c81a6.tar.gz |
Merge branch 'fix-default-branch' into 'master'
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
See merge request !614
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/services/git_push_service.rb | 4 | ||||
-rw-r--r-- | spec/services/git_push_service_spec.rb | 15 |
3 files changed, 19 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG index c7fb49dc183..90e9d96e7ce 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Please view this file on the master branch, on stable branches it's out of date. v 7.11.0 (unreleased) + - Make the first branch pushed to an empty repository the default HEAD (Stan Hu) - Make Reply-To config apply to change e-mail confirmation and other Devise notifications (Stan Hu) - Add application setting to restrict user signups to e-mail domains (Stan Hu) - Don't allow a merge request to be merged when its title starts with "WIP". 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 diff --git a/spec/services/git_push_service_spec.rb b/spec/services/git_push_service_spec.rb index af37e8319a4..e7558f28768 100644 --- a/spec/services/git_push_service_spec.rb +++ b/spec/services/git_push_service_spec.rb @@ -234,5 +234,18 @@ describe GitPushService do expect(Issue.find(issue.id)).to be_opened end end -end + describe "empty project" do + let(:project) { create(:project_empty_repo) } + let(:new_ref) { 'refs/heads/feature'} + + before do + allow(project).to receive(:default_branch).and_return('feature') + expect(project).to receive(:change_head) { 'feature'} + end + + it 'push to first branch updates HEAD' do + service.execute(project, user, @blankrev, @newrev, new_ref) + end + end +end |