Skip to content

Commit 1b17c58

Browse files
committed
fix(diff): Support files renaming between revisions for a diff
Solves #1
1 parent 28c4082 commit 1b17c58

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/asciidoctor-git-include.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ def process doc, reader, target, attributes
1616
lines = attributes.fetch('lines', '')
1717
as_diff = attributes.value?('diff') || attributes.key?('diff')
1818
diff_revision = attributes.fetch('diff', "#{revision}~1")
19+
target_before = attributes.fetch('difftarget', target)
1920

2021
cmd = %(git -C #{repository} show #{revision}:#{target})
2122
if (as_diff)
22-
cmd = %(git -C #{repository} diff #{diff_revision}:#{target} #{revision}:#{target})
23+
cmd = %(git -C #{repository} diff #{diff_revision}:#{target_before} #{revision}:#{target})
2324
end
2425
content = %x(#{cmd})
2526

test/extension_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@ class ExtensionTest < Minitest::Test
105105
assert_match(/-messages = \["Hello"\]/, output)
106106
assert_match(/\+messages = \["Hello", "World", "!!!"\]/, output)
107107
end
108+
109+
test 'it includes a diff for specific revisions of a file that is renamed' do
110+
input = <<-EOS
111+
include::git@test/fixtures/file-after-rename.adoc[revision=28c4082,diff=6d5eaf1,difftarget=test/fixtures/file-before-rename.adoc]
112+
EOS
113+
114+
output = render_embedded_string input
115+
116+
assert_match(/diff --git a\/test\/fixtures\/file-before-rename.adoc b\/test\/fixtures\/file-after-rename.adoc/, output)
117+
assert_match(/-Contents before rename./, output)
118+
assert_match(/\+Contents after rename./, output)
119+
end
108120
end
109121

110122
def given_file_committed_to_fresh_repo(file_name, content)

0 commit comments

Comments
 (0)