summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Duncalfe <lduncalfe@eml.cc>2019-06-07 17:10:42 +1200
committerLuke Duncalfe <lduncalfe@eml.cc>2019-06-19 12:55:10 +1200
commit2b6d1c560e6d9f06aa0feef340a7e9b47385b572 (patch)
tree29d706da58687e65f75afcb1bcbb865284874583
parentbb34f09fbe04b9cc915211c1af262068ef792994 (diff)
downloadgitlab-ce-9490-static-gitattributes-for-design-repos-ce.tar.gz
CE backport for changes in EE MR 140179490-static-gitattributes-for-design-repos-ce
This backports to CE changes to allow the EE model DesignManagement::Repository to override the #attributes_at method to provide its own git attributes. The #attributes_at method was freely available, as it's never called by anything in the app. It looks like the code that called it got refactored out of existence in ca66a04f. It was still being called in a spec https://gitlab.com/gitlab-org/gitlab-ce/blob/85b29c1c2fa3b94d7371cf454c485457a0756cb1/spec/services/files/create_service_spec.rb#L40 which I've left because with the change in Lfs::FileTransformer in fact is now again the perfect test! See EE MR https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/14017 And these comment threads https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/13894#note_178002089 https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/13894#note_178049984
-rw-r--r--app/services/lfs/file_transformer.rb10
-rw-r--r--lib/gitlab/git/repository.rb9
-rw-r--r--spec/support/shared_examples/controllers/repository_lfs_file_load_examples.rb12
3 files changed, 24 insertions, 7 deletions
diff --git a/app/services/lfs/file_transformer.rb b/app/services/lfs/file_transformer.rb
index d1746399908..88f59b820a4 100644
--- a/app/services/lfs/file_transformer.rb
+++ b/app/services/lfs/file_transformer.rb
@@ -4,6 +4,14 @@ module Lfs
# Usage: Calling `new_file` check to see if a file should be in LFS and
# return a transformed result with `content` and `encoding` to commit.
#
+ # The `repository` passed to the initializer can be a Repository or
+ # a DesignManagement::Repository (an EE-specific class that inherits
+ # from Repository).
+ #
+ # The `repository_type` property will be one of the types named in
+ # `Gitlab::GlRepository.types`, and is recorded on the `LfsObjectsProject`
+ # in order to identify the repository location of the blob.
+ #
# For LFS an LfsObject linked to the project is stored and an LFS
# pointer returned. If the file isn't in LFS the untransformed content
# is returned to save in the commit.
@@ -52,7 +60,7 @@ module Lfs
end
def cached_attributes
- @cached_attributes ||= Gitlab::Git::AttributesAtRefParser.new(repository, branch_name)
+ @cached_attributes ||= repository.attributes_at(branch_name)
end
# rubocop: disable CodeReuse/ActiveRecord
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index 8a2e711ec4e..a6739f12280 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -683,17 +683,16 @@ module Gitlab
attributes(path)[name]
end
- # Check .gitattributes for a given ref
+ # Returns parsed .gitattributes for a given ref
#
- # This only checks the root .gitattributes file,
+ # This only parses the root .gitattributes file,
# it does not traverse subfolders to find additional .gitattributes files
#
# This method is around 30 times slower than `attributes`, which uses
# `$GIT_DIR/info/attributes`. Consider caching AttributesAtRefParser
# and reusing that for multiple calls instead of this method.
- def attributes_at(ref, file_path)
- parser = AttributesAtRefParser.new(self, ref)
- parser.attributes(file_path)
+ def attributes_at(ref)
+ AttributesAtRefParser.new(self, ref)
end
def languages(ref = nil)
diff --git a/spec/support/shared_examples/controllers/repository_lfs_file_load_examples.rb b/spec/support/shared_examples/controllers/repository_lfs_file_load_examples.rb
index b7080c68270..d3cadf2ba7c 100644
--- a/spec/support/shared_examples/controllers/repository_lfs_file_load_examples.rb
+++ b/spec/support/shared_examples/controllers/repository_lfs_file_load_examples.rb
@@ -9,7 +9,15 @@
# - `filepath`: path of the file (contains filename)
# - `subject`: the request to be made to the controller. Example:
# subject { get :show, namespace_id: project.namespace, project_id: project }
-shared_examples 'a controller that can serve LFS files' do
+#
+# The LFS disabled scenario can be skipped by passing `skip_lfs_disabled_tests: true`
+# when including the examples (Note, at time of writing this is only used by
+# an EE-specific spec):
+#
+# it_behaves_like 'a controller that can serve LFS files', skip_lfs_disabled_tests: true do
+# ...
+# end
+shared_examples 'a controller that can serve LFS files' do |options = {}|
let(:lfs_oid) { '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897' }
let(:lfs_size) { '1575078' }
let!(:lfs_object) { create(:lfs_object, oid: lfs_oid, size: lfs_size) }
@@ -83,6 +91,8 @@ shared_examples 'a controller that can serve LFS files' do
end
it 'delivers ASCII file' do
+ skip 'Calling spec asked to skip testing LFS disabled scenario' if options[:skip_lfs_disabled_tests]
+
subject
expect(response).to have_gitlab_http_status(200)