Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Then, inside your AsciiDoc file, use an `include` statement like normal, pointin
* `revision` - repository revision to use (default: `HEAD`)
* `lines` - specify the lines to include (i.e. `lines=2..5;10;12`)
* `diff` - include a patch for the given `revision`, or between two revisions (see examples)
* `ignorewhitespaces` - whether to ignore whitespaces and newlines changes in an included patch

// tag::examples[]

Expand Down Expand Up @@ -103,4 +104,12 @@ To generate a patch for changes between two revisions (b015e8dd and b015e8dd):
\include::git@path/within/repo/file.rb[revision=b015e8dd,diff=0245ac72]
----

=== Including a patch ignoring whitespaces

To generate a patch for changes introduced in a specific revision (b015e8dd) but ignoring the changes related to whitespaces and caret line return:

----
\include::git@path/within/repo/file.rb[revision=b015e8dd,diff,ignorewhitespaces]
----

// end::examples[]
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
7 changes: 7 additions & 0 deletions test/fixtures/lots_of_whitespaces.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@



Some line with some content

Another line with more content that has changed