From e8e79ce77dc92dca9fb6c43b01c3b1116de963b6 Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Wed, 26 Apr 2023 00:27:19 +0200 Subject: [PATCH 1/3] add basic diff test --- test/commit_test.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/commit_test.rb b/test/commit_test.rb index 12f20aba0..404267628 100644 --- a/test/commit_test.rb +++ b/test/commit_test.rb @@ -362,6 +362,21 @@ def test_commit_summary commit = Rugged::Commit.lookup(@repo, commit_id) assert_equal "This is the commit message", commit.summary end + + def test_diff + oid = "5b5b025afb0b4c913b4c338a42934a3863bf3644" + obj = @repo.lookup(oid) + + assert_equal <<-PATCH, obj.diff.patch +diff --git b/new.txt a/new.txt +new file mode 100644 +index 0000000..fa49b07 +--- /dev/null ++++ a/new.txt +@@ -0,0 +1 @@ ++new file + PATCH + end end class CommitWriteTest < Rugged::TestCase From ac3251d5343fd86a1547ed4f813e206b52b1912a Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Wed, 26 Apr 2023 00:28:24 +0200 Subject: [PATCH 2/3] test options as hash passed to commit#diff is not changed --- test/commit_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/commit_test.rb b/test/commit_test.rb index 404267628..720bcc6cf 100644 --- a/test/commit_test.rb +++ b/test/commit_test.rb @@ -377,6 +377,15 @@ def test_diff +new file PATCH end + + def test_diff_options_not_changing + oid = "5b5b025afb0b4c913b4c338a42934a3863bf3644" + obj = @repo.lookup(oid) + + options = {} + + assert_equal obj.diff(options).patch, obj.diff(options).patch + end end class CommitWriteTest < Rugged::TestCase From 92c7d58209b3ea1a1f48504482651ec2602d1398 Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Wed, 26 Apr 2023 00:28:41 +0200 Subject: [PATCH 3/3] don't change options hash passed to commit#diff --- lib/rugged/commit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rugged/commit.rb b/lib/rugged/commit.rb index 81db6813a..4c8da1ab7 100644 --- a/lib/rugged/commit.rb +++ b/lib/rugged/commit.rb @@ -34,7 +34,7 @@ def diff(*args) # then diff against the prior commit if args.empty? || args.first.is_a?(Hash) other = parents.first - opts[:reverse] = !opts[:reverse] + opts = opts.merge(:reverse => !opts[:reverse]) end self.tree.diff(other, opts) end