From ad9ae16d8a44dd2523bd6e6109db9fe2da45d3a5 Mon Sep 17 00:00:00 2001 From: Krasimir Angelov Date: Thu, 30 May 2019 18:40:53 +1200 Subject: 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 --- app/presenters/ci/build_runner_presenter.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'app/presenters') diff --git a/app/presenters/ci/build_runner_presenter.rb b/app/presenters/ci/build_runner_presenter.rb index 6d46e0bf18a..471b6d3b726 100644 --- a/app/presenters/ci/build_runner_presenter.rb +++ b/app/presenters/ci/build_runner_presenter.rb @@ -25,14 +25,16 @@ module Ci end def git_depth - strong_memoize(:git_depth) do - git_depth = variables&.find { |variable| variable[:key] == 'GIT_DEPTH' }&.dig(:value) - git_depth.to_i - end + if git_depth_variable + git_depth_variable[:value] + else + project.default_git_depth + end.to_i end def refspecs specs = [] + specs << refspec_for_merge_request_ref if merge_request_ref? if git_depth > 0 specs << refspec_for_branch(ref) if branch? || legacy_detached_merge_request_pipeline? @@ -42,8 +44,6 @@ module Ci specs << refspec_for_tag end - specs << refspec_for_merge_request_ref if merge_request_ref? - specs end @@ -89,5 +89,11 @@ module Ci def refspec_for_merge_request_ref "+#{ref}:#{ref}" end + + def git_depth_variable + strong_memoize(:git_depth_variable) do + variables&.find { |variable| variable[:key] == 'GIT_DEPTH' } + end + end end end -- cgit v1.2.3