From 31f2608161945d3c1189509955d68209934e2988 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Mon, 9 Jul 2018 06:29:46 -0700 Subject: [PATCH] Fix handling of annotated tags when Gitaly is not in use Attempting to view an annotated tag in the TreeController would result in `NoMethodError: undefined method 'tree'` when Rugged was in use. `Blob#find_by_rugged` assumes that the ref is a true. Using the commit ID ensures that the right ref is being used. Note that in 11.1, `Blob#find` no longer uses Rugged, so this is only a bug in 11.0. Closes gitlab-org/gitlab-ce#47797 --- .../unreleased/sh-fix-issue-47797-ce.yml | 5 ++++ lib/extracts_path.rb | 5 ++++ spec/lib/extracts_path_spec.rb | 26 +++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 changelogs/unreleased/sh-fix-issue-47797-ce.yml diff --git a/changelogs/unreleased/sh-fix-issue-47797-ce.yml b/changelogs/unreleased/sh-fix-issue-47797-ce.yml new file mode 100644 index 00000000000..456d96acacb --- /dev/null +++ b/changelogs/unreleased/sh-fix-issue-47797-ce.yml @@ -0,0 +1,5 @@ +--- +title: Fix handling of annotated tags when Gitaly is not in use +merge_request: +author: +type: fixed diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb index a9b04c183ad..e8dbde176ef 100644 --- a/lib/extracts_path.rb +++ b/lib/extracts_path.rb @@ -139,6 +139,11 @@ module ExtractsPath def lfs_blob_ids blob_ids = tree.blobs.map(&:id) + + # When current endpoint is a Blob then `tree.blobs` will be empty, it means we need to analyze + # the current Blob in order to determine if it's a LFS object + blob_ids = Array.wrap(@repo.blob_at(@commit.id, @path)&.id) if blob_ids.empty? # rubocop:disable Gitlab/ModuleWithInstanceVariables + @lfs_blob_ids = Gitlab::Git::Blob.batch_lfs_pointers(@project.repository, blob_ids).map(&:id) # rubocop:disable Gitlab/ModuleWithInstanceVariables end diff --git a/spec/lib/extracts_path_spec.rb b/spec/lib/extracts_path_spec.rb index e13406d1972..8947e2ac4fb 100644 --- a/spec/lib/extracts_path_spec.rb +++ b/spec/lib/extracts_path_spec.rb @@ -203,4 +203,30 @@ describe ExtractsPath do expect(extract_ref_without_atom('foo.atom')).to eq(nil) end end + + describe '#lfs_blob_ids' do + shared_examples '#lfs_blob_ids' do + let(:tag) { @project.repository.add_tag(@project.owner, 'my-annotated-tag', 'master', 'test tag') } + let(:ref) { tag.target } + let(:params) { { ref: ref, path: 'README.md' } } + + before do + @project = create(:project, :repository) + end + + it 'handles annotated tags' do + assign_ref_vars + + expect(lfs_blob_ids).to eq([]) + end + end + + context 'when gitaly is enabled' do + it_behaves_like '#lfs_blob_ids' + end + + context 'when gitaly is disabled', :skip_gitaly_mock do + it_behaves_like '#lfs_blob_ids' + end + end end -- GitLab