diff options
author | Krasimir Angelov <kangelov@gitlab.com> | 2019-05-30 09:40:53 +0300 |
---|---|---|
committer | Fabio Pitino <fpitino@gitlab.com> | 2019-06-06 11:21:18 +0300 |
commit | ad9ae16d8a44dd2523bd6e6109db9fe2da45d3a5 (patch) | |
tree | ee8445389c89b4c7f5cc71c3d35f469345a5016f /app/services/projects/fork_service.rb | |
parent | 3fd99b4e7a58843943ade87a3658d477278aa412 (diff) |
Add project level git depth setting
Introduce default_git_depth in project's CI/CD settings and set it to
50. Use it if there is no GIT_DEPTH variable specified. Apply this
default only to newly created projects and keep it nil for old ones
in order to not break pipelines that rely on non-shallow clones.
default_git_depth can be updated from CI/CD Settings in the UI, must be
either nil or integer between 0 and 1000 (incl).
Inherit default_git_depth from the origin project when forking projects.
MR pipelines are run on a MR ref (refs/merge-requests/:iid/merge) and it
contains unique commit (i.e. merge commit) which doesn't exist in the
other branch/tags refs. We need to add it cause otherwise it may break
pipelines for old projects that have already enabled Pipelines for merge
results and have git depth 0.
Document new default_git_depth project CI/CD setting
Diffstat (limited to 'app/services/projects/fork_service.rb')
-rw-r--r-- | app/services/projects/fork_service.rb | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/app/services/projects/fork_service.rb b/app/services/projects/fork_service.rb index fc234bafc57..14c1c98ea73 100644 --- a/app/services/projects/fork_service.rb +++ b/app/services/projects/fork_service.rb @@ -36,18 +36,19 @@ module Projects def fork_new_project new_params = { - visibility_level: allowed_visibility_level, - description: @project.description, - name: target_name, - path: target_path, - shared_runners_enabled: @project.shared_runners_enabled, - namespace_id: target_namespace.id, - fork_network: fork_network, + visibility_level: allowed_visibility_level, + description: @project.description, + name: target_name, + path: target_path, + 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 }, # 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 # exception. - relations_block: -> (project) { build_fork_network_member(project) } + relations_block: -> (project) { build_fork_network_member(project) } } if @project.avatar.present? && @project.avatar.image? @@ -56,7 +57,10 @@ module Projects new_params.merge!(@project.object_pool_params) - new_project = CreateService.new(current_user, new_params).execute + new_project = CreateService.new(current_user, new_params).execute do |p| + p.build_ci_cd_settings(default_git_depth: @project.default_git_depth) + end + return new_project unless new_project.persisted? # Set the forked_from_project relation after saving to avoid having to |