diff --git a/lib/asciidoctor-git-include.rb b/lib/asciidoctor-git-include.rb index 009d8ae..bb4986e 100644 --- a/lib/asciidoctor-git-include.rb +++ b/lib/asciidoctor-git-include.rb @@ -16,10 +16,11 @@ def process doc, reader, target, attributes lines = attributes.fetch('lines', '') as_diff = attributes.value?('diff') || attributes.key?('diff') diff_revision = attributes.fetch('diff', "#{revision}~1") + ignore_whitespaces_option = attributes.value?('ignorewhitespaces') || attributes.key?('ignorewhitespaces') ? '--ignore-cr-at-eol --ignore-space-at-eol -w -b --ignore-blank-lines' : '' cmd = %(git -C #{repository} show #{revision}:#{target}) if (as_diff) - cmd = %(git -C #{repository} diff #{diff_revision}:#{target} #{revision}:#{target}) + cmd = %(git -C #{repository} diff #{ignore_whitespaces_option} #{diff_revision}:#{target} #{revision}:#{target}) end content = %x(#{cmd}) diff --git a/test/extension_test.rb b/test/extension_test.rb index 60e2d8f..3dc72e7 100644 --- a/test/extension_test.rb +++ b/test/extension_test.rb @@ -105,6 +105,19 @@ class ExtensionTest < Minitest::Test assert_match(/-messages = \["Hello"\]/, output) assert_match(/\+messages = \["Hello", "World", "!!!"\]/, output) end + + test 'it includes a diff ignoring whitespaces and caret returns' do + input = <<-EOS +include::git@test/fixtures/lots_of_whitespaces.adoc[revision=e80ca3c,diff=2c2f9a9,ignorewhitespaces] + EOS + + output = render_embedded_string input + + assert_match(/diff --git a\/test\/fixtures\/lots_of_whitespaces.adoc b\/test\/fixtures\/lots_of_whitespaces.adoc/, output) + assert_match(/-Another line with more content/, output) + assert_match(/\+Another line with more content that has changed/, output) + refute_match(/-Some line with some content/, output) + end end def given_file_committed_to_fresh_repo(file_name, content)