From b278d886ba65e2d3d438352b6243cd33b1ba4636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Fri, 9 Nov 2018 22:17:43 +0100 Subject: Support both ref and ref-name in protected_for? --- app/models/project.rb | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/models/project.rb b/app/models/project.rb index f5dc58cd67f..61840c972ee 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -36,6 +36,7 @@ class Project < ActiveRecord::Base extend Gitlab::ConfigHelper BoardLimitExceeded = Class.new(StandardError) + AmbiguousRef = Class.new(StandardError) STATISTICS_ATTRIBUTE = 'repositories_count'.freeze NUMBER_OF_PERMITTED_BOARDS = 1 @@ -1160,6 +1161,21 @@ class Project < ActiveRecord::Base end end + def resolve_ref(ref) + tag_exists = repository.tag_exists?(ref) + branch_exists = repository.branch_exists?(ref) + + if tag_exists && branch_exists + raise AmbiguousRef + elsif tag_exists + Gitlab::Git::TAG_REF_PREFIX + ref + elsif branch_exists + Gitlab::Git::BRANCH_REF_PREFIX + ref + else + ref + end + end + def root_ref?(branch) repository.root_ref == branch end @@ -1737,10 +1753,13 @@ class Project < ActiveRecord::Base end def protected_for?(ref) - if repository.branch_exists?(ref) - ProtectedBranch.protected?(self, ref) - elsif repository.tag_exists?(ref) - ProtectedTag.protected?(self, ref) + full_ref = resolve_ref(ref) + ref_name = Gitlab::Git.ref_name(full_ref) + + if Gitlab::Git.branch_ref?(full_ref) + ProtectedBranch.protected?(self, ref_name) + elsif Gitlab::Git.tag_ref?(full_ref) + ProtectedTag.protected?(self, ref_name) end end -- cgit v1.2.1 From 1bf580688890a3b13e7ac0468f29108dafe08f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Sat, 10 Nov 2018 14:34:53 +0100 Subject: Use full ref when possible to avoid ambiguity --- app/models/ci/build.rb | 5 +++-- app/models/ci/pipeline.rb | 3 ++- app/models/concerns/has_ref.rb | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 app/models/concerns/has_ref.rb (limited to 'app') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index d86a6eceb59..f5c21481f63 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -10,6 +10,7 @@ module Ci include Importable include Gitlab::Utils::StrongMemoize include Deployable + include HasRef belongs_to :project, inverse_of: :builds belongs_to :runner @@ -640,11 +641,11 @@ module Ci def secret_group_variables return [] unless project.group - project.group.ci_variables_for(ref, project) + project.group.ci_variables_for(git_ref, project) end def secret_project_variables(environment: persisted_environment) - project.ci_variables_for(ref: ref, environment: environment) + project.ci_variables_for(ref: git_ref, environment: environment) end def steps diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index d06022a0fb7..a1a11d2f7ab 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -11,6 +11,7 @@ module Ci include Gitlab::Utils::StrongMemoize include AtomicInternalId include EnumWithNil + include HasRef belongs_to :project, inverse_of: :all_pipelines belongs_to :user @@ -588,7 +589,7 @@ module Ci end def protected_ref? - strong_memoize(:protected_ref) { project.protected_for?(ref) } + strong_memoize(:protected_ref) { project.protected_for?(git_ref) } end def legacy_trigger diff --git a/app/models/concerns/has_ref.rb b/app/models/concerns/has_ref.rb new file mode 100644 index 00000000000..79816841f7f --- /dev/null +++ b/app/models/concerns/has_ref.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module HasRef + extend ActiveSupport::Concern + + def branch? + !tag? + end + + private + + def git_ref + if branch? + Gitlab::Git::BRANCH_REF_PREFIX + ref.to_s + elsif tag? + Gitlab::Git::TAG_REF_PREFIX + ref.to_s + else + raise ArgumentError, 'Invalid pipeline type!' + end + end +end -- cgit v1.2.1 From 837ab8c5d83243db8efe1cec1c6e001d1cbeb43f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Thu, 15 Nov 2018 21:28:17 +0100 Subject: Make HasRef#git_ref public --- app/models/concerns/has_ref.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'app') diff --git a/app/models/concerns/has_ref.rb b/app/models/concerns/has_ref.rb index 79816841f7f..d7089294efc 100644 --- a/app/models/concerns/has_ref.rb +++ b/app/models/concerns/has_ref.rb @@ -7,15 +7,11 @@ module HasRef !tag? end - private - def git_ref if branch? Gitlab::Git::BRANCH_REF_PREFIX + ref.to_s elsif tag? Gitlab::Git::TAG_REF_PREFIX + ref.to_s - else - raise ArgumentError, 'Invalid pipeline type!' end end end -- cgit v1.2.1 From 855e7c32b9f3541fec085726d338802c8ca9b9f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Thu, 15 Nov 2018 22:54:21 +0100 Subject: Use Gitlab::Git::Ref in Project#resolve_ref Reworks Project#resolve_ref to return Gitlab::Git::Branch, Gitlab::Git::Tag or raise an AmbiguousRef error. --- app/models/project.rb | 11 ++++++----- app/models/repository.rb | 10 ++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/models/project.rb b/app/models/project.rb index 61840c972ee..6893f76dda9 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1168,11 +1168,11 @@ class Project < ActiveRecord::Base if tag_exists && branch_exists raise AmbiguousRef elsif tag_exists - Gitlab::Git::TAG_REF_PREFIX + ref + repository.find_tag(ref) elsif branch_exists - Gitlab::Git::BRANCH_REF_PREFIX + ref + repository.find_branch(ref) else - ref + repository.find_ref(ref) end end @@ -1753,8 +1753,9 @@ class Project < ActiveRecord::Base end def protected_for?(ref) - full_ref = resolve_ref(ref) - ref_name = Gitlab::Git.ref_name(full_ref) + resolved_ref = resolve_ref(ref) + full_ref = resolved_ref.full_ref + ref_name = resolved_ref.name if Gitlab::Git.branch_ref?(full_ref) ProtectedBranch.protected?(self, ref_name) diff --git a/app/models/repository.rb b/app/models/repository.rb index 35dd120856d..10635eb0cf4 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -182,6 +182,16 @@ class Repository tags.find { |tag| tag.name == name } end + def find_ref(ref) + if Gitlab::Git.tag_ref?(ref) + find_tag(Gitlab::Git.ref_name(ref)) + elsif Gitlab::Git.branch_ref?(ref) + find_branch(Gitlab::Git.ref_name(ref)) + else + nil + end + end + def add_branch(user, branch_name, ref) branch = raw_repository.add_branch(branch_name, user: user, target: ref) -- cgit v1.2.1 From b0b5924eb418851ddfab848ab16b6acac27d42e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Thu, 15 Nov 2018 23:31:02 +0100 Subject: Use nil instead of raising AmbiguousRef --- app/models/project.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/models/project.rb b/app/models/project.rb index 6893f76dda9..e1acfbe7770 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -36,7 +36,6 @@ class Project < ActiveRecord::Base extend Gitlab::ConfigHelper BoardLimitExceeded = Class.new(StandardError) - AmbiguousRef = Class.new(StandardError) STATISTICS_ATTRIBUTE = 'repositories_count'.freeze NUMBER_OF_PERMITTED_BOARDS = 1 @@ -1166,7 +1165,7 @@ class Project < ActiveRecord::Base branch_exists = repository.branch_exists?(ref) if tag_exists && branch_exists - raise AmbiguousRef + nil elsif tag_exists repository.find_tag(ref) elsif branch_exists @@ -1754,6 +1753,8 @@ class Project < ActiveRecord::Base def protected_for?(ref) resolved_ref = resolve_ref(ref) + return false unless resolved_ref + full_ref = resolved_ref.full_ref ref_name = resolved_ref.name -- cgit v1.2.1 From 38348aa1215daa2393b7d488c1ca8926d67dc09e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Fri, 16 Nov 2018 13:20:52 +0100 Subject: Remove Gitlab::Git::Ref#full_ref --- app/models/project.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/models/project.rb b/app/models/project.rb index e1acfbe7770..22ce916a36c 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1755,13 +1755,11 @@ class Project < ActiveRecord::Base resolved_ref = resolve_ref(ref) return false unless resolved_ref - full_ref = resolved_ref.full_ref - ref_name = resolved_ref.name - - if Gitlab::Git.branch_ref?(full_ref) - ProtectedBranch.protected?(self, ref_name) - elsif Gitlab::Git.tag_ref?(full_ref) - ProtectedTag.protected?(self, ref_name) + case resolved_ref + when Gitlab::Git::Branch + ProtectedBranch.protected?(self, resolved_ref.name) + when Gitlab::Git::Tag + ProtectedTag.protected?(self, resolved_ref.name) end end -- cgit v1.2.1 From 96a0a8cfb62d9ea66ee2a22e09a116d64f333703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Fri, 16 Nov 2018 21:03:21 +0100 Subject: Use strings instead of Gitlab::Git::Ref --- app/models/project.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'app') diff --git a/app/models/project.rb b/app/models/project.rb index 22ce916a36c..e9fa9cfabc9 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1167,11 +1167,11 @@ class Project < ActiveRecord::Base if tag_exists && branch_exists nil elsif tag_exists - repository.find_tag(ref) + Gitlab::Git::TAG_REF_PREFIX + ref elsif branch_exists - repository.find_branch(ref) + Gitlab::Git::BRANCH_REF_PREFIX + ref else - repository.find_ref(ref) + ref end end @@ -1755,11 +1755,12 @@ class Project < ActiveRecord::Base resolved_ref = resolve_ref(ref) return false unless resolved_ref - case resolved_ref - when Gitlab::Git::Branch - ProtectedBranch.protected?(self, resolved_ref.name) - when Gitlab::Git::Tag - ProtectedTag.protected?(self, resolved_ref.name) + ref_name = Gitlab::Git.ref_name(resolved_ref) + + if Gitlab::Git.branch_ref?(resolved_ref) + ProtectedBranch.protected?(self, ref_name) + elsif Gitlab::Git.tag_ref?(resolved_ref) + ProtectedTag.protected?(self, ref_name) end end -- cgit v1.2.1 From e0b5306cb79c7a535f96c0d2d864278b2193d641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Fri, 16 Nov 2018 21:06:58 +0100 Subject: Remove Repository#find_ref --- app/models/repository.rb | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'app') diff --git a/app/models/repository.rb b/app/models/repository.rb index 10635eb0cf4..35dd120856d 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -182,16 +182,6 @@ class Repository tags.find { |tag| tag.name == name } end - def find_ref(ref) - if Gitlab::Git.tag_ref?(ref) - find_tag(Gitlab::Git.ref_name(ref)) - elsif Gitlab::Git.branch_ref?(ref) - find_branch(Gitlab::Git.ref_name(ref)) - else - nil - end - end - def add_branch(user, branch_name, ref) branch = raw_repository.add_branch(branch_name, user: user, target: ref) -- cgit v1.2.1 From 24d682254a0ae68dfc605fc077c6a7610b97994a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Tue, 20 Nov 2018 15:07:25 +0100 Subject: Move Project#resolve_ref to Repository --- app/models/project.rb | 17 +---------------- app/models/repository.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-) (limited to 'app') diff --git a/app/models/project.rb b/app/models/project.rb index e9fa9cfabc9..2ba273c6f98 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1160,21 +1160,6 @@ class Project < ActiveRecord::Base end end - def resolve_ref(ref) - tag_exists = repository.tag_exists?(ref) - branch_exists = repository.branch_exists?(ref) - - if tag_exists && branch_exists - nil - elsif tag_exists - Gitlab::Git::TAG_REF_PREFIX + ref - elsif branch_exists - Gitlab::Git::BRANCH_REF_PREFIX + ref - else - ref - end - end - def root_ref?(branch) repository.root_ref == branch end @@ -1752,7 +1737,7 @@ class Project < ActiveRecord::Base end def protected_for?(ref) - resolved_ref = resolve_ref(ref) + resolved_ref = repository.resolve_ref(ref) return false unless resolved_ref ref_name = Gitlab::Git.ref_name(resolved_ref) diff --git a/app/models/repository.rb b/app/models/repository.rb index 35dd120856d..221d01c5b44 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -182,6 +182,21 @@ class Repository tags.find { |tag| tag.name == name } end + def resolve_ref(ref) + tag_exists = tag_exists?(ref) + branch_exists = branch_exists?(ref) + + if tag_exists && branch_exists + nil + elsif tag_exists + Gitlab::Git::TAG_REF_PREFIX + ref + elsif branch_exists + Gitlab::Git::BRANCH_REF_PREFIX + ref + else + ref + end + end + def add_branch(user, branch_name, ref) branch = raw_repository.add_branch(branch_name, user: user, target: ref) -- cgit v1.2.1 From 350ea9c55ab6b980ac5ec74d2a34b9cbac915e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Fri, 23 Nov 2018 00:11:42 +0100 Subject: Implement Repository#ambiguous_ref? This implements Repository#ambiguous_ref? and checks if a ref is ambiguous before trying to resolve the ref in Project#protected_for? --- app/models/project.rb | 6 +++--- app/models/repository.rb | 13 ++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'app') diff --git a/app/models/project.rb b/app/models/project.rb index 2ba273c6f98..800c8afb49f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1737,10 +1737,10 @@ class Project < ActiveRecord::Base end def protected_for?(ref) - resolved_ref = repository.resolve_ref(ref) - return false unless resolved_ref + return false unless ref && !repository.ambiguous_ref?(ref) - ref_name = Gitlab::Git.ref_name(resolved_ref) + resolved_ref = repository.resolve_ref(ref) + ref_name = resolved_ref == ref ? Gitlab::Git.ref_name(resolved_ref) : ref if Gitlab::Git.branch_ref?(resolved_ref) ProtectedBranch.protected?(self, ref_name) diff --git a/app/models/repository.rb b/app/models/repository.rb index 221d01c5b44..9e01f7f0df5 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -182,15 +182,14 @@ class Repository tags.find { |tag| tag.name == name } end - def resolve_ref(ref) - tag_exists = tag_exists?(ref) - branch_exists = branch_exists?(ref) + def ambiguous_ref?(ref) + tag_exists?(ref) && branch_exists?(ref) + end - if tag_exists && branch_exists - nil - elsif tag_exists + def resolve_ref(ref) + if tag_exists?(ref) Gitlab::Git::TAG_REF_PREFIX + ref - elsif branch_exists + elsif branch_exists?(ref) Gitlab::Git::BRANCH_REF_PREFIX + ref else ref -- cgit v1.2.1 From 9f6d228d2368911befc11038d64ccb9ccae131ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Mon, 26 Nov 2018 15:04:51 +0100 Subject: Simplify conditionals in Project#protected_ref? --- app/models/project.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/models/project.rb b/app/models/project.rb index 800c8afb49f..fa1820b2bdb 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1737,10 +1737,14 @@ class Project < ActiveRecord::Base end def protected_for?(ref) - return false unless ref && !repository.ambiguous_ref?(ref) + return false if ref.nil? || repository.ambiguous_ref?(ref) resolved_ref = repository.resolve_ref(ref) - ref_name = resolved_ref == ref ? Gitlab::Git.ref_name(resolved_ref) : ref + ref_name = if resolved_ref == ref + Gitlab::Git.ref_name(resolved_ref) + else + ref + end if Gitlab::Git.branch_ref?(resolved_ref) ProtectedBranch.protected?(self, ref_name) -- cgit v1.2.1 From 63da51900c205981fc12cda25778265d78b607e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Tue, 27 Nov 2018 14:45:25 +0100 Subject: Make full ref in Repository#resolve_ref explicit --- app/models/repository.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/models/repository.rb b/app/models/repository.rb index 9e01f7f0df5..3db49a5fce0 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -191,7 +191,7 @@ class Repository Gitlab::Git::TAG_REF_PREFIX + ref elsif branch_exists?(ref) Gitlab::Git::BRANCH_REF_PREFIX + ref - else + elsif Gitlab::Git.tag_ref?(ref) || Gitlab::Git.branch_ref?(ref) ref end end -- cgit v1.2.1 From dfe7f57eef0c5c2319c5c9898ba0721b6a1c9913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Wed, 28 Nov 2018 15:18:14 +0100 Subject: Rename Repository#resolve_ref to expand_ref --- app/models/project.rb | 13 +++++++------ app/models/repository.rb | 4 +--- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'app') diff --git a/app/models/project.rb b/app/models/project.rb index fa1820b2bdb..a8bef70f505 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1739,12 +1739,13 @@ class Project < ActiveRecord::Base def protected_for?(ref) return false if ref.nil? || repository.ambiguous_ref?(ref) - resolved_ref = repository.resolve_ref(ref) - ref_name = if resolved_ref == ref - Gitlab::Git.ref_name(resolved_ref) - else - ref - end + if Gitlab::Git.branch_ref?(ref) || Gitlab::Git.tag_ref?(ref) + resolved_ref = ref + ref_name = Gitlab::Git.ref_name(ref) + else + resolved_ref = repository.expand_ref(ref) + ref_name = ref + end if Gitlab::Git.branch_ref?(resolved_ref) ProtectedBranch.protected?(self, ref_name) diff --git a/app/models/repository.rb b/app/models/repository.rb index 3db49a5fce0..7352386d9d5 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -186,13 +186,11 @@ class Repository tag_exists?(ref) && branch_exists?(ref) end - def resolve_ref(ref) + def expand_ref(ref) if tag_exists?(ref) Gitlab::Git::TAG_REF_PREFIX + ref elsif branch_exists?(ref) Gitlab::Git::BRANCH_REF_PREFIX + ref - elsif Gitlab::Git.tag_ref?(ref) || Gitlab::Git.branch_ref?(ref) - ref end end -- cgit v1.2.1 From 08942de9b6a3ad361cbae8a83a8e8b7c7e4768ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Wed, 28 Nov 2018 15:43:58 +0100 Subject: Raise an error on ambiguous refs --- app/models/project.rb | 3 ++- app/models/repository.rb | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/models/project.rb b/app/models/project.rb index a8bef70f505..9a9ef5c2fa9 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1737,7 +1737,8 @@ class Project < ActiveRecord::Base end def protected_for?(ref) - return false if ref.nil? || repository.ambiguous_ref?(ref) + return false if ref.nil? + raise Repository::AmbiguousRefError if repository.ambiguous_ref?(ref) if Gitlab::Git.branch_ref?(ref) || Gitlab::Git.tag_ref?(ref) resolved_ref = ref diff --git a/app/models/repository.rb b/app/models/repository.rb index 7352386d9d5..c685752c294 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -26,6 +26,7 @@ class Repository delegate :bundle_to_disk, to: :raw_repository CreateTreeError = Class.new(StandardError) + AmbiguousRefError = Class.new(StandardError) # Methods that cache data from the Git repository. # -- cgit v1.2.1 From 0f00c7818bf09e800c4ac6652077fffe7976ed6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Fri, 30 Nov 2018 11:34:59 +0100 Subject: Remove resolving conditional from protected_for --- app/models/project.rb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/models/project.rb b/app/models/project.rb index 9a9ef5c2fa9..f71bf65f417 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1740,13 +1740,8 @@ class Project < ActiveRecord::Base return false if ref.nil? raise Repository::AmbiguousRefError if repository.ambiguous_ref?(ref) - if Gitlab::Git.branch_ref?(ref) || Gitlab::Git.tag_ref?(ref) - resolved_ref = ref - ref_name = Gitlab::Git.ref_name(ref) - else - resolved_ref = repository.expand_ref(ref) - ref_name = ref - end + resolved_ref = repository.expand_ref(ref) + ref_name = Gitlab::Git.ref_name(resolved_ref) if Gitlab::Git.branch_ref?(resolved_ref) ProtectedBranch.protected?(self, ref_name) -- cgit v1.2.1 From 93d3c61eca258369bda0c28c5519cb14e4ff1457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Fri, 30 Nov 2018 12:18:53 +0100 Subject: Add specs when full ref is passed to protected_for --- app/models/project.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/models/project.rb b/app/models/project.rb index f71bf65f417..0948e4625a8 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1740,7 +1740,7 @@ class Project < ActiveRecord::Base return false if ref.nil? raise Repository::AmbiguousRefError if repository.ambiguous_ref?(ref) - resolved_ref = repository.expand_ref(ref) + resolved_ref = repository.expand_ref(ref) || ref ref_name = Gitlab::Git.ref_name(resolved_ref) if Gitlab::Git.branch_ref?(resolved_ref) -- cgit v1.2.1 From 44374434b5a0b4297686d5388f1124eda3adcbff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Fri, 30 Nov 2018 13:07:55 +0100 Subject: Conditionally assign ref_name for more efficiency --- app/models/project.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/models/project.rb b/app/models/project.rb index 0948e4625a8..79414665001 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1741,7 +1741,11 @@ class Project < ActiveRecord::Base raise Repository::AmbiguousRefError if repository.ambiguous_ref?(ref) resolved_ref = repository.expand_ref(ref) || ref - ref_name = Gitlab::Git.ref_name(resolved_ref) + ref_name = if resolved_ref == ref + Gitlab::Git.ref_name(resolved_ref) + else + ref + end if Gitlab::Git.branch_ref?(resolved_ref) ProtectedBranch.protected?(self, ref_name) -- cgit v1.2.1 From 1b28a2c1a9c9651316997f7e12b161b68001126b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Mon, 3 Dec 2018 14:10:42 +0100 Subject: Check resolved_ref before checking if protected --- app/models/project.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/models/project.rb b/app/models/project.rb index 79414665001..d75fecb5ff2 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1737,10 +1737,11 @@ class Project < ActiveRecord::Base end def protected_for?(ref) - return false if ref.nil? raise Repository::AmbiguousRefError if repository.ambiguous_ref?(ref) resolved_ref = repository.expand_ref(ref) || ref + return false unless Gitlab::Git.tag_ref?(resolved_ref) || Gitlab::Git.branch_ref?(resolved_ref) + ref_name = if resolved_ref == ref Gitlab::Git.ref_name(resolved_ref) else -- cgit v1.2.1 From 6cd0965233822fe31366d0763633de6bb11d8d72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Sat, 8 Dec 2018 19:39:47 +0100 Subject: Support merge_request pipeline ref types --- app/models/ci/pipeline.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index a1a11d2f7ab..4f64fff88ac 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -389,7 +389,7 @@ module Ci end def branch? - !tag? && !merge_request? + super && !merge_request? end def stuck? @@ -721,14 +721,10 @@ module Ci end def git_ref - if branch? + if merge_request? Gitlab::Git::BRANCH_REF_PREFIX + ref.to_s - elsif merge_request? - Gitlab::Git::BRANCH_REF_PREFIX + ref.to_s - elsif tag? - Gitlab::Git::TAG_REF_PREFIX + ref.to_s else - raise ArgumentError, 'Invalid pipeline type!' + super end end -- cgit v1.2.1