From 64a9e53bd16092e869f88e42a3e69f3f4ba0a23e Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Fri, 17 Nov 2017 17:57:48 +0000 Subject: Fix conflict highlighting Conflicts used to take a `Repository` and pass that to `Gitlab::Highlight.highlight`, which would call `#gitattribute` on the repository. Now they use a `Gitlab::Git::Repository`, which didn't have that method defined - but defining it on `Gitlab::Git::Repository` does make it available on `Repository` through `method_missing`, so we can do that and both cases will work. --- app/models/repository.rb | 4 ---- lib/gitlab/git/repository.rb | 4 ++++ spec/lib/gitlab/conflict/file_spec.rb | 7 +++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 35ee12bdfa1..214f2daa199 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -994,10 +994,6 @@ class Repository raw_repository.ls_files(actual_ref) end - def gitattribute(path, name) - raw_repository.attributes(path)[name] - end - def copy_gitattributes(ref) actual_ref = ref || root_ref begin diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index cfb88a0c12b..b97d07187ae 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -984,6 +984,10 @@ module Gitlab @attributes.attributes(path) end + def gitattribute(path, name) + attributes(path)[name] + end + def languages(ref = nil) Gitlab::GitalyClient.migrate(:commit_languages) do |is_enabled| if is_enabled diff --git a/spec/lib/gitlab/conflict/file_spec.rb b/spec/lib/gitlab/conflict/file_spec.rb index bf981d2f6f6..92792144429 100644 --- a/spec/lib/gitlab/conflict/file_spec.rb +++ b/spec/lib/gitlab/conflict/file_spec.rb @@ -84,6 +84,13 @@ describe Gitlab::Conflict::File do expect(line.text).to eq(html_to_text(line.rich_text)) end end + + # This spec will break if Rouge's highlighting changes, but we need to + # ensure that the lines are actually highlighted. + it 'highlights the lines correctly' do + expect(conflict_file.lines.first.rich_text) + .to eq("module Gitlab\n") + end end describe '#sections' do -- cgit v1.2.1