Merge pull request #461 from abf/rosa-build:446-default_branch

Aliased projects should have same default branch
This commit is contained in:
avokhmin 2015-03-11 02:37:33 +04:00
commit ba84f0f916
4 changed files with 26 additions and 6 deletions

View File

@ -48,9 +48,7 @@ class Projects::ProjectsController < Projects::BaseController
end end
def edit def edit
@project_aliases = Project.where.not(id: @project.id). @project_aliases = Project.project_aliases(@project).paginate(page: current_page)
where('alias_from_id IN (:ids) OR id IN (:ids)', { ids: [@project.alias_from_id, @project.id] }).
paginate(page: current_page)
end end
def create def create

View File

@ -63,7 +63,10 @@ module Project::DefaultBranch
# Private: Set git head. # Private: Set git head.
def set_new_git_head def set_new_git_head
`cd #{path} && git symbolic-ref HEAD refs/heads/#{self.default_branch}` if self.default_branch_changed? && self.repo.branches.map(&:name).include?(self.default_branch) if default_branch_changed? && repo.branches.map(&:name).include?(default_branch)
repo.git.send(:'symbolic-ref', {}, 'HEAD', "refs/heads/#{default_branch}")
Project.project_aliases(self).update_all default_branch: default_branch
end
end end
# Private: Validation for checking that the default branch is exist. # Private: Validation for checking that the default branch is exist.

View File

@ -93,6 +93,11 @@ class Project < ActiveRecord::Base
(projects.owner_id in (?) AND projects.owner_type = 'User')", group_owner_ids, user_owner_ids) (projects.owner_id in (?) AND projects.owner_type = 'User')", group_owner_ids, user_owner_ids)
} }
scope :project_aliases, ->(project) {
where.not(id: project.id).
where('alias_from_id IN (:ids) OR id IN (:ids)', { ids: [project.alias_from_id, project.id].compact })
}
before_validation :truncate_name, on: :create before_validation :truncate_name, on: :create
before_save -> { self.owner_uname = owner.uname if owner_uname.blank? || owner_id_changed? || owner_type_changed? } before_save -> { self.owner_uname = owner.uname if owner_uname.blank? || owner_id_changed? || owner_type_changed? }
before_create :set_maintainer before_create :set_maintainer

View File

@ -4,7 +4,7 @@ describe Project do
before { stub_symlink_methods } before { stub_symlink_methods }
context '#fork' do context '#fork' do
let(:root_project) { FactoryGirl.create(:project) } let(:root_project) { FactoryGirl.create(:project_with_commit) }
let(:child_project) { root_project.fork(FactoryGirl.create(:user)) } let(:child_project) { root_project.fork(FactoryGirl.create(:user)) }
let(:child_child_project) { child_project.fork(FactoryGirl.create(:user)) } let(:child_child_project) { child_project.fork(FactoryGirl.create(:user)) }
let(:alias_project) { root_project.fork(FactoryGirl.create(:user), is_alias: true) } let(:alias_project) { root_project.fork(FactoryGirl.create(:user), is_alias: true) }
@ -41,6 +41,20 @@ describe Project do
expect(alias_alias_project.alias_from).to eq(root_project) expect(alias_alias_project.alias_from).to eq(root_project)
expect{ Grit::Repo.new(alias_alias_project.path) }.to_not raise_exception expect{ Grit::Repo.new(alias_alias_project.path) }.to_not raise_exception
end end
it 'ensures that aliased projects have a same default branch' do
new_default_branch = 'conflicts'
alias_project.update_attributes default_branch: new_default_branch
expect(alias_project.parent.default_branch).to eq(new_default_branch)
end
it 'ensures that forked project allowed to have another default branch' do
fill_project root_project
fill_project child_project
new_default_branch = 'conflicts'
child_project.update_attributes default_branch: new_default_branch
expect(child_project.parent.default_branch).to_not eq(new_default_branch)
end
end end
context 'for destroy' do context 'for destroy' do