Skip to content

Commit 64a2a0c

Browse files
author
Edward Thomson
committed
Test Index.merge_file with missing sides
`Index.merge_file` produces the conflict file for a given conflict. This can be produced for add/add conflicts (that are missing ancestors) but - by definition - cannot be produced for edit/delete conflicts. (Git simply leaves the edited file in the working tree without conflict markup.) Validate that we handle this case correctly.
1 parent 4429cca commit 64a2a0c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/index_test.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,31 @@ def test_merge_file_with_labels
289289
assert_equal merge_file_result[:path], "conflicts-one.txt"
290290
assert_equal merge_file_result[:data], "<<<<<<< ours\nThis is most certainly a conflict!\n=======\nThis is a conflict!!!\n>>>>>>> theirs\n"
291291
end
292+
293+
def test_merge_file_without_ancestor
294+
# remove the stage 1 (ancestor), this is now an add/add conflict
295+
@repo.index.remove("conflicts-one.txt", 1)
296+
merge_file_result = @repo.index.merge_file("conflicts-one.txt", our_label: "ours", their_label: "theirs")
297+
assert !merge_file_result[:automergeable]
298+
assert_equal merge_file_result[:path], "conflicts-one.txt"
299+
assert_equal merge_file_result[:data], "<<<<<<< ours\nThis is most certainly a conflict!\n=======\nThis is a conflict!!!\n>>>>>>> theirs\n"
300+
end
301+
302+
def test_merge_file_without_ours
303+
# turn this into a modify/delete conflict
304+
@repo.index.remove("conflicts-one.txt", 2)
305+
assert_raises RuntimeError do
306+
@repo.index.merge_file("conflicts-one.txt", our_label: "ours", their_label: "theirs")
307+
end
308+
end
309+
310+
def test_merge_file_without_theirs
311+
# turn this into a modify/delete conflict
312+
@repo.index.remove("conflicts-one.txt", 3)
313+
assert_raises RuntimeError do
314+
@repo.index.merge_file("conflicts-one.txt", our_label: "ours", their_label: "theirs")
315+
end
316+
end
292317
end
293318

294319
class IndexRepositoryTest < Rugged::TestCase

0 commit comments

Comments
 (0)