summaryrefslogtreecommitdiff
path: root/app/models/project.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-08-31 07:03:12 +0000
committerDouwe Maan <douwe@gitlab.com>2017-08-31 07:03:12 +0000
commiteacda4cc98933c2c9bfd4935b289eee79da516dd (patch)
treec3f42466af59edd6f6ff0da7b8334e75112221a2 /app/models/project.rb
parentf7c8434c7100c3c87eb2a75cd5a128e520d8c110 (diff)
parenta882026bdfc770ecfac70bfc88a409ec010f06c9 (diff)
downloadgitlab-ce-eacda4cc98933c2c9bfd4935b289eee79da516dd.tar.gz
Merge branch '36743-existing-repo-master' into 'master'
[master] Prevent project creation (blank, import or fork) when repository already exists on disk See merge request gitlab/gitlabhq!2169
Diffstat (limited to 'app/models/project.rb')
-rw-r--r--app/models/project.rb23
1 files changed, 21 insertions, 2 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index d5324ceac31..b2c70777e97 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -222,6 +222,7 @@ class Project < ActiveRecord::Base
validates :import_url, importable_url: true, if: [:external_import?, :import_url_changed?]
validates :star_count, numericality: { greater_than_or_equal_to: 0 }
validate :check_limit, on: :create
+ validate :can_create_repository?, on: [:create, :update], if: ->(project) { !project.persisted? || project.renamed? }
validate :avatar_type,
if: ->(project) { project.avatar.present? && project.avatar_changed? }
validates :avatar, file_size: { maximum: 200.kilobytes.to_i }
@@ -468,7 +469,7 @@ class Project < ActiveRecord::Base
end
def repository_storage_path
- Gitlab.config.repositories.storages[repository_storage]['path']
+ Gitlab.config.repositories.storages[repository_storage].try(:[], 'path')
end
def team
@@ -583,7 +584,7 @@ class Project < ActiveRecord::Base
end
def valid_import_url?
- valid? || errors.messages[:import_url].nil?
+ valid?(:import_url) || errors.messages[:import_url].nil?
end
def create_or_update_import_data(data: nil, credentials: nil)
@@ -1000,6 +1001,20 @@ class Project < ActiveRecord::Base
end
end
+ # Check if repository already exists on disk
+ def can_create_repository?
+ return false unless repository_storage_path
+
+ expires_full_path_cache # we need to clear cache to validate renames correctly
+
+ if gitlab_shell.exists?(repository_storage_path, "#{disk_path}.git")
+ errors.add(:base, 'There is already a repository with that name on disk')
+ return false
+ end
+
+ true
+ end
+
def create_repository(force: false)
# Forked import is handled asynchronously
return if forked? && !force
@@ -1486,6 +1501,10 @@ class Project < ActiveRecord::Base
self.storage_version.nil?
end
+ def renamed?
+ persisted? && path_changed?
+ end
+
private
def storage