Commit 52673a91 authored by Krasimir Angelov's avatar Krasimir Angelov

Forks get default_git_depth 0 if the origin is nil

If the origin project has no default_git_depth set (i.e. nil) set the
fork's default_git_depth to 0
parent ad9ae16d
......@@ -8,7 +8,7 @@ class ProjectCiCdSetting < ApplicationRecord
DEFAULT_GIT_DEPTH = 50
before_create :set_default_git_depth, unless: :default_git_depth?
before_create :set_default_git_depth
validates :default_git_depth,
numericality: {
......@@ -31,6 +31,8 @@ class ProjectCiCdSetting < ApplicationRecord
private
def set_default_git_depth
return if default_git_depth
self.default_git_depth = DEFAULT_GIT_DEPTH
end
end
......@@ -43,7 +43,7 @@ module Projects
shared_runners_enabled: @project.shared_runners_enabled,
namespace_id: target_namespace.id,
fork_network: fork_network,
ci_cd_settings_attributes: { default_git_depth: @project.default_git_depth },
ci_cd_settings_attributes: { default_git_depth: @project.default_git_depth || 0 },
# We need to assign the fork network membership after the project has
# been instantiated to avoid ActiveRecord trying to create it when
# initializing the project, as that would cause a foreign key constraint
......@@ -57,10 +57,7 @@ module Projects
new_params.merge!(@project.object_pool_params)
new_project = CreateService.new(current_user, new_params).execute do |p|
p.build_ci_cd_settings(default_git_depth: @project.default_git_depth)
end
new_project = CreateService.new(current_user, new_params).execute
return new_project unless new_project.persisted?
# Set the forked_from_project relation after saving to avoid having to
......
......@@ -37,10 +37,10 @@ describe ProjectCiCdSetting do
it 'does not set default value if present' do
project = build(:project)
project.build_ci_cd_settings(default_git_depth: 42)
project.build_ci_cd_settings(default_git_depth: 0)
project.save!
expect(project.reload.ci_cd_settings.default_git_depth).to eq(42)
expect(project.reload.ci_cd_settings.default_git_depth).to eq(0)
end
end
end
......@@ -146,10 +146,26 @@ describe Projects::ForkService do
end
context "CI/CD settings" do
it "inherits default_git_depth from the origin project" do
@from_project.update(default_git_depth: 42)
@to_project = fork_project(@from_project, @to_user)
expect(@to_project.default_git_depth).to eq(42)
let(:to_project) { fork_project(@from_project, @to_user) }
context "when origin has git depth specified" do
before do
@from_project.update(default_git_depth: 42)
end
it "inherits default_git_depth from the origin project" do
expect(to_project.default_git_depth).to eq(42)
end
end
context "when origin does not define git depth" do
before do
@from_project.update!(default_git_depth: nil)
end
it "the fork has git depth set to 0" do
expect(to_project.default_git_depth).to eq(0)
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment