Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop mutating commit diff options #961

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion lib/rugged/commit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions test/commit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,30 @@ 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

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
Expand Down