diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2019-07-08 13:40:32 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2019-07-08 13:40:32 +0000 |
commit | 734f0240cc0eb8a86b0eab33f1abfe6db207669e (patch) | |
tree | 8d57ee38162a63aaf191f65752d6a962718d75bb /app | |
parent | 7c7b8f32a7145dcac0f16488221181e50e1bb4da (diff) | |
parent | f8d6f7322ea43ff7844d006885db9f0c36ad7cc9 (diff) | |
download | gitlab-ce-734f0240cc0eb8a86b0eab33f1abfe6db207669e.tar.gz |
Merge branch 'run-pipeline-for-merge-train-at-train-ref-ce' into 'master'
CE Port: Fix race condition of `refs/merge` competing overwrite
See merge request gitlab-org/gitlab-ce!30308
Diffstat (limited to 'app')
-rw-r--r-- | app/models/merge_request.rb | 13 | ||||
-rw-r--r-- | app/models/repository.rb | 4 |
2 files changed, 17 insertions, 0 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index e96e26cc773..53977748c30 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -1127,6 +1127,19 @@ class MergeRequest < ApplicationRecord "refs/#{Repository::REF_MERGE_REQUEST}/#{iid}/merge" end + def train_ref_path + "refs/#{Repository::REF_MERGE_REQUEST}/#{iid}/train" + end + + def cleanup_refs(only: :all) + target_refs = [] + target_refs << ref_path if %i[all head].include?(only) + target_refs << merge_ref_path if %i[all merge].include?(only) + target_refs << train_ref_path if %i[all train].include?(only) + + project.repository.delete_refs(*target_refs) + end + def self.merge_request_ref?(ref) ref.start_with?("refs/#{Repository::REF_MERGE_REQUEST}/") end diff --git a/app/models/repository.rb b/app/models/repository.rb index a408db7ebbe..a25d5abfa64 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -845,6 +845,10 @@ class Repository raw.merge_to_ref(user, source_sha, branch, target_ref, message, first_parent_ref) end + def delete_refs(*ref_names) + raw.delete_refs(*ref_names) + end + def ff_merge(user, source, target_branch, merge_request: nil) their_commit_id = commit(source)&.id raise 'Invalid merge source' if their_commit_id.nil? |