diff options
author | Marin Jankovski <maxlazio@gmail.com> | 2017-08-31 10:45:28 +0200 |
---|---|---|
committer | Marin Jankovski <maxlazio@gmail.com> | 2017-08-31 10:45:28 +0200 |
commit | 7d38df306c73af354286cecb24b19155e537797b (patch) | |
tree | 64ae59f2ed74c3d878d0216ca998d451fce74740 /app/models/project.rb | |
parent | 3e092caa91853afeab3bb01be10869e45c39de5d (diff) | |
parent | eacda4cc98933c2c9bfd4935b289eee79da516dd (diff) | |
download | gitlab-ce-7d38df306c73af354286cecb24b19155e537797b.tar.gz |
Merge branch 'master' of dev.gitlab.org:gitlab/gitlabhq
Diffstat (limited to 'app/models/project.rb')
-rw-r--r-- | app/models/project.rb | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 9d7bea4eb66..6c679236da6 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 } @@ -464,7 +465,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 @@ -579,7 +580,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) @@ -996,6 +997,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 @@ -1482,6 +1497,10 @@ class Project < ActiveRecord::Base self.storage_version.nil? end + def renamed? + persisted? && path_changed? + end + private def storage |