Commit 0d2537bf authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '9490-static-gitattributes-for-design-repos-ce' into 'master'

CE backport for changes in EE MR 14017

See merge request gitlab-org/gitlab-ce!29328
parents 96c2949d dcf811ba
...@@ -4,6 +4,14 @@ module Lfs ...@@ -4,6 +4,14 @@ module Lfs
# Usage: Calling `new_file` check to see if a file should be in LFS and # 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. # 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 # 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 # pointer returned. If the file isn't in LFS the untransformed content
# is returned to save in the commit. # is returned to save in the commit.
...@@ -52,7 +60,7 @@ module Lfs ...@@ -52,7 +60,7 @@ module Lfs
end end
def cached_attributes def cached_attributes
@cached_attributes ||= Gitlab::Git::AttributesAtRefParser.new(repository, branch_name) @cached_attributes ||= repository.attributes_at(branch_name)
end end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
......
...@@ -683,17 +683,16 @@ module Gitlab ...@@ -683,17 +683,16 @@ module Gitlab
attributes(path)[name] attributes(path)[name]
end 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 # it does not traverse subfolders to find additional .gitattributes files
# #
# This method is around 30 times slower than `attributes`, which uses # This method is around 30 times slower than `attributes`, which uses
# `$GIT_DIR/info/attributes`. Consider caching AttributesAtRefParser # `$GIT_DIR/info/attributes`. Consider caching AttributesAtRefParser
# and reusing that for multiple calls instead of this method. # and reusing that for multiple calls instead of this method.
def attributes_at(ref, file_path) def attributes_at(ref)
parser = AttributesAtRefParser.new(self, ref) AttributesAtRefParser.new(self, ref)
parser.attributes(file_path)
end end
def languages(ref = nil) def languages(ref = nil)
......
...@@ -9,7 +9,15 @@ ...@@ -9,7 +9,15 @@
# - `filepath`: path of the file (contains filename) # - `filepath`: path of the file (contains filename)
# - `subject`: the request to be made to the controller. Example: # - `subject`: the request to be made to the controller. Example:
# subject { get :show, namespace_id: project.namespace, project_id: project } # 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_oid) { '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897' }
let(:lfs_size) { '1575078' } let(:lfs_size) { '1575078' }
let!(:lfs_object) { create(:lfs_object, oid: lfs_oid, size: lfs_size) } 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 ...@@ -83,6 +91,8 @@ shared_examples 'a controller that can serve LFS files' do
end end
it 'delivers ASCII file' do it 'delivers ASCII file' do
skip 'Calling spec asked to skip testing LFS disabled scenario' if options[:skip_lfs_disabled_tests]
subject subject
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment