Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ci/build.rb11
-rw-r--r--app/models/commit.rb2
-rw-r--r--app/models/pages_domain.rb2
-rw-r--r--app/models/project.rb22
-rw-r--r--app/models/repository.rb67
5 files changed, 42 insertions, 62 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 83fe23606d1..6012dbba1b9 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -79,7 +79,7 @@ module Ci
before_save :ensure_token
before_destroy { unscoped_project }
- after_create do |build|
+ after_create unless: :importing? do |build|
run_after_commit { BuildHooksWorker.perform_async(build.id) }
end
@@ -461,7 +461,14 @@ module Ci
end
def cache
- [options[:cache]]
+ cache = options[:cache]
+
+ if cache && project.jobs_cache_index
+ cache = cache.merge(
+ key: "#{cache[:key]}:#{project.jobs_cache_index}")
+ end
+
+ [cache]
end
def credentials
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 2be07ca7d3c..39d7f5b159d 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -371,7 +371,7 @@ class Commit
#
# Returns a symbol
def uri_type(path)
- entry = @raw.tree.path(path)
+ entry = @raw.rugged_tree_entry(path)
if entry[:type] == :blob
blob = ::Blob.decorate(Gitlab::Git::Blob.new(name: entry[:name]), @project)
blob.image? || blob.video? ? :raw : :blob
diff --git a/app/models/pages_domain.rb b/app/models/pages_domain.rb
index 8de42ff9d2e..d8bf54e0c40 100644
--- a/app/models/pages_domain.rb
+++ b/app/models/pages_domain.rb
@@ -27,7 +27,7 @@ class PagesDomain < ActiveRecord::Base
def url
return unless domain
- if certificate
+ if certificate.present?
"https://#{domain}"
else
"http://#{domain}"
diff --git a/app/models/project.rb b/app/models/project.rb
index 4cb9d9fe637..fbe65e700a4 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1450,6 +1450,7 @@ class Project < ActiveRecord::Base
import_finish
remove_import_jid
update_project_counter_caches
+ after_create_default_branch
end
def update_project_counter_caches
@@ -1463,6 +1464,27 @@ class Project < ActiveRecord::Base
end
end
+ def after_create_default_branch
+ return unless default_branch
+
+ # Ensure HEAD points to the default branch in case it is not master
+ change_head(default_branch)
+
+ if current_application_settings.default_branch_protection != Gitlab::Access::PROTECTION_NONE && !ProtectedBranch.protected?(self, default_branch)
+ params = {
+ name: default_branch,
+ push_access_levels_attributes: [{
+ access_level: current_application_settings.default_branch_protection == Gitlab::Access::PROTECTION_DEV_CAN_PUSH ? Gitlab::Access::DEVELOPER : Gitlab::Access::MASTER
+ }],
+ merge_access_levels_attributes: [{
+ access_level: current_application_settings.default_branch_protection == Gitlab::Access::PROTECTION_DEV_CAN_MERGE ? Gitlab::Access::DEVELOPER : Gitlab::Access::MASTER
+ }]
+ }
+
+ ProtectedBranches::CreateService.new(self, creator, params).execute(skip_authorization: true)
+ end
+ end
+
def remove_import_jid
return unless import_jid
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 7b8f5794a87..9c879e2006b 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -783,34 +783,30 @@ class Repository
end
def create_dir(user, path, **options)
- options[:user] = user
options[:actions] = [{ action: :create_dir, file_path: path }]
- multi_action(**options)
+ multi_action(user, **options)
end
def create_file(user, path, content, **options)
- options[:user] = user
options[:actions] = [{ action: :create, file_path: path, content: content }]
- multi_action(**options)
+ multi_action(user, **options)
end
def update_file(user, path, content, **options)
previous_path = options.delete(:previous_path)
action = previous_path && previous_path != path ? :move : :update
- options[:user] = user
options[:actions] = [{ action: action, file_path: path, previous_path: previous_path, content: content }]
- multi_action(**options)
+ multi_action(user, **options)
end
def delete_file(user, path, **options)
- options[:user] = user
options[:actions] = [{ action: :delete, file_path: path }]
- multi_action(**options)
+ multi_action(user, **options)
end
def with_cache_hooks
@@ -824,59 +820,14 @@ class Repository
result.newrev
end
- def with_branch(user, *args)
- with_cache_hooks do
- Gitlab::Git::OperationService.new(user, raw_repository).with_branch(*args) do |start_commit|
- yield start_commit
- end
- end
- end
-
- # rubocop:disable Metrics/ParameterLists
- def multi_action(
- user:, branch_name:, message:, actions:,
- author_email: nil, author_name: nil,
- start_branch_name: nil, start_project: project)
-
- with_branch(
- user,
- branch_name,
- start_branch_name: start_branch_name,
- start_repository: start_project.repository.raw_repository) do |start_commit|
-
- index = Gitlab::Git::Index.new(raw_repository)
-
- if start_commit
- index.read_tree(start_commit.rugged_commit.tree)
- parents = [start_commit.sha]
- else
- parents = []
- end
+ def multi_action(user, **options)
+ start_project = options.delete(:start_project)
- actions.each do |options|
- index.public_send(options.delete(:action), options) # rubocop:disable GitlabSecurity/PublicSend
- end
-
- options = {
- tree: index.write_tree,
- message: message,
- parents: parents
- }
- options.merge!(get_committer_and_author(user, email: author_email, name: author_name))
-
- create_commit(options)
+ if start_project
+ options[:start_repository] = start_project.repository.raw_repository
end
- end
- # rubocop:enable Metrics/ParameterLists
- def get_committer_and_author(user, email: nil, name: nil)
- committer = user_to_committer(user)
- author = Gitlab::Git.committer_hash(email: email, name: name) || committer
-
- {
- author: author,
- committer: committer
- }
+ with_cache_hooks { raw.multi_action(user, **options) }
end
def can_be_merged?(source_sha, target_branch)