summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrasimir Angelov <kangelov@gitlab.com>2019-06-06 23:08:01 +1200
committerKrasimir Angelov <kangelov@gitlab.com>2019-06-06 23:22:50 +1200
commit52673a916df0f759262afa1aaa230f7d62efd554 (patch)
tree0635538d8bf562e914c0bb44f1580cf9d56aa5f3
parentad9ae16d8a44dd2523bd6e6109db9fe2da45d3a5 (diff)
downloadgitlab-ce-52673a916df0f759262afa1aaa230f7d62efd554.tar.gz
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
-rw-r--r--app/models/project_ci_cd_setting.rb4
-rw-r--r--app/services/projects/fork_service.rb7
-rw-r--r--spec/models/project_ci_cd_setting_spec.rb4
-rw-r--r--spec/services/projects/fork_service_spec.rb24
4 files changed, 27 insertions, 12 deletions
diff --git a/app/models/project_ci_cd_setting.rb b/app/models/project_ci_cd_setting.rb
index cf1f80fd1ef..9e7d921c229 100644
--- a/app/models/project_ci_cd_setting.rb
+++ b/app/models/project_ci_cd_setting.rb
@@ -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
diff --git a/app/services/projects/fork_service.rb b/app/services/projects/fork_service.rb
index 14c1c98ea73..f1bad2d9b15 100644
--- a/app/services/projects/fork_service.rb
+++ b/app/services/projects/fork_service.rb
@@ -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
diff --git a/spec/models/project_ci_cd_setting_spec.rb b/spec/models/project_ci_cd_setting_spec.rb
index 80f75f45e43..c5a4c242b70 100644
--- a/spec/models/project_ci_cd_setting_spec.rb
+++ b/spec/models/project_ci_cd_setting_spec.rb
@@ -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
diff --git a/spec/services/projects/fork_service_spec.rb b/spec/services/projects/fork_service_spec.rb
index e8a38287a63..3211a6e1310 100644
--- a/spec/services/projects/fork_service_spec.rb
+++ b/spec/services/projects/fork_service_spec.rb
@@ -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