Skip to content

Commit

Permalink
feat(diff): give capability to ignore whitespaces and caret returns i…
Browse files Browse the repository at this point in the history
…n a diff

Solves #2
  • Loading branch information
edeweerd1A committed Feb 5, 2025
1 parent e80ca3c commit 9f74a61
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/asciidoctor-git-include.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
13 changes: 13 additions & 0 deletions test/extension_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9f74a61

Please sign in to comment.