Skip to content

Commit 1f9dc2b

Browse files
committed
revert: Add tests
1 parent ed574b1 commit 1f9dc2b

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

test/revert_test.rb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
require "test_helper"
2+
3+
class RevertTest < Rugged::TestCase
4+
def setup
5+
@repo = FixtureRepo.from_libgit2("revert")
6+
end
7+
8+
def verify_index(index, expected)
9+
assert index.is_a?(Rugged::Index)
10+
assert_equal expected.count, index.count
11+
expected.each_with_index do |(mode, oid, stage, path), i|
12+
entry = index[i]
13+
assert entry
14+
assert_equal path, entry[:path]
15+
assert_equal mode, entry[:mode]
16+
assert_equal oid, entry[:oid]
17+
assert_equal stage, entry[:stage]
18+
end
19+
end
20+
21+
def test_revert_automerge
22+
expected = [
23+
[0100644, "caf99de3a49827117bb66721010eac461b06a80c", 0, "file1.txt"],
24+
[0100644, "0ab09ea6d4c3634bdf6c221626d8b6f7dd890767", 0, "file2.txt"],
25+
[0100644, "f4e107c230d08a60fb419d19869f1f282b272d9c", 0, "file3.txt"],
26+
[0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 0, "file6.txt"]]
27+
28+
ours = Rugged::Commit.lookup(@repo, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45")
29+
revert = Rugged::Commit.lookup(@repo, "d1d403d22cbe24592d725f442835cf46fe60c8ac")
30+
31+
index = @repo.revert_commit(revert, ours)
32+
verify_index(index, expected)
33+
end
34+
35+
def test_revert_with_conflicts
36+
expected = [
37+
[0100644, "7731926a337c4eaba1e2187d90ebfa0a93659382", 1, "file1.txt"],
38+
[0100644, "4b8fcff56437e60f58e9a6bc630dd242ebf6ea2c", 2, "file1.txt"],
39+
[0100644, "3a3ef367eaf3fe79effbfb0a56b269c04c2b59fe", 3, "file1.txt"],
40+
[0100644, "0ab09ea6d4c3634bdf6c221626d8b6f7dd890767", 0, "file2.txt"],
41+
[0100644, "f4e107c230d08a60fb419d19869f1f282b272d9c", 0, "file3.txt"],
42+
[0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 0, "file6.txt"]]
43+
44+
revert = Rugged::Commit.lookup(@repo, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45")
45+
46+
index = @repo.revert_commit(revert, "HEAD")
47+
assert index.conflicts?
48+
verify_index(index, expected)
49+
50+
index = @repo.revert_commit(revert, "HEAD", :fail_on_conflict => true)
51+
refute index
52+
end
53+
54+
def test_revert_orphan
55+
expected = [
56+
[0100644, "296a6d3be1dff05c5d1f631d2459389fa7b619eb", 0, "file-mainline.txt"]]
57+
58+
head = Rugged::Commit.lookup(@repo,"39467716290f6df775a91cdb9a4eb39295018145")
59+
revert = Rugged::Commit.lookup(@repo, "ebb03002cee5d66c7732dd06241119fe72ab96a5")
60+
61+
index = @repo.revert_commit(revert, head)
62+
verify_index(index, expected)
63+
end
64+
end

0 commit comments

Comments
 (0)