[#446] aliased projects should have same default branch
This commit is contained in:
parent
535ef43364
commit
4026b75784
|
@ -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
|
||||||
|
|
|
@ -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 self.default_branch_changed? && self.repo.branches.map(&:name).include?(self.default_branch)
|
||||||
|
self.repo.git.send(:'symbolic-ref', {}, 'HEAD', "refs/heads/#{self.default_branch}")
|
||||||
|
Project.project_aliases(self).update_all default_branch: self.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.
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
@ -229,7 +243,7 @@ describe Project do
|
||||||
url = 'http://abf-downloads.rosalinux.ru/abf_personal/repository/test-mass-import'
|
url = 'http://abf-downloads.rosalinux.ru/abf_personal/repository/test-mass-import'
|
||||||
visibility = 'open'
|
visibility = 'open'
|
||||||
|
|
||||||
|
|
||||||
Project.run_mass_import(url, "abf-worker-service-1-3.src.rpm\nredir-2.2.1-7.res6.src.rpm\n", visibility, owner, repository.id)
|
Project.run_mass_import(url, "abf-worker-service-1-3.src.rpm\nredir-2.2.1-7.res6.src.rpm\n", visibility, owner, repository.id)
|
||||||
|
|
||||||
Project.count.should == 2
|
Project.count.should == 2
|
||||||
|
|
Loading…
Reference in New Issue