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
path: root/lib
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-11-06 19:10:25 +0300
committerDouwe Maan <douwe@gitlab.com>2017-11-06 19:10:25 +0300
commita48d0595ab4cbe7c828fe5d580269948a485eddf (patch)
tree4ea1d304a2f77630a0c1f25a989800354dd028ee /lib
parentad118080cf32e011cd9ded053a86334fea67ffb2 (diff)
parentdf7564333400488f554ab889e2ee7269aba6ada1 (diff)
Merge branch 'jej/fs-prevent-push-when-missing-objects' into 'master'
Prevent git push when LFS objects are missing Closes #24564 See merge request gitlab-org/gitlab-ce!13837
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/checks/change_access.rb12
-rw-r--r--lib/gitlab/checks/lfs_integrity.rb24
2 files changed, 35 insertions, 1 deletions
diff --git a/lib/gitlab/checks/change_access.rb b/lib/gitlab/checks/change_access.rb
index b6805230348..ef92fc5a0a0 100644
--- a/lib/gitlab/checks/change_access.rb
+++ b/lib/gitlab/checks/change_access.rb
@@ -12,7 +12,8 @@ module Gitlab
change_existing_tags: 'You are not allowed to change existing tags on this project.',
update_protected_tag: 'Protected tags cannot be updated.',
delete_protected_tag: 'Protected tags cannot be deleted.',
- create_protected_tag: 'You are not allowed to create this tag as it is protected.'
+ create_protected_tag: 'You are not allowed to create this tag as it is protected.',
+ lfs_objects_missing: 'LFS objects are missing. Ensure LFS is properly set up or try a manual "git lfs push --all".'
}.freeze
attr_reader :user_access, :project, :skip_authorization, :protocol
@@ -36,6 +37,7 @@ module Gitlab
push_checks
branch_checks
tag_checks
+ lfs_objects_exist_check
true
end
@@ -136,6 +138,14 @@ module Gitlab
def matching_merge_request?
Checks::MatchingMergeRequest.new(@newrev, @branch_name, @project).match?
end
+
+ def lfs_objects_exist_check
+ lfs_check = Checks::LfsIntegrity.new(project, @newrev)
+
+ if lfs_check.objects_missing?
+ raise GitAccess::UnauthorizedError, ERROR_MESSAGES[:lfs_objects_missing]
+ end
+ end
end
end
end
diff --git a/lib/gitlab/checks/lfs_integrity.rb b/lib/gitlab/checks/lfs_integrity.rb
new file mode 100644
index 00000000000..27a95764dc1
--- /dev/null
+++ b/lib/gitlab/checks/lfs_integrity.rb
@@ -0,0 +1,24 @@
+module Gitlab
+ module Checks
+ class LfsIntegrity
+ REV_LIST_OBJECT_LIMIT = 2_000
+
+ def initialize(project, newrev)
+ @project = project
+ @newrev = newrev
+ end
+
+ def objects_missing?
+ return false unless @newrev && @project.lfs_enabled?
+
+ new_lfs_pointers = Gitlab::Git::LfsChanges.new(@project.repository, @newrev).new_pointers(object_limit: REV_LIST_OBJECT_LIMIT)
+
+ return false unless new_lfs_pointers.present?
+
+ existing_count = @project.lfs_objects.where(oid: new_lfs_pointers.map(&:lfs_oid)).count
+
+ existing_count != new_lfs_pointers.count
+ end
+ end
+ end
+end