Skip to content

Commit a3eba26

Browse files
author
Vicent Martí
authored
Merge pull request #630 from libgit2/ethomson/merge_file_raise_on_missing_side
Index.merge_file: raise when conflict is missing one side
2 parents 4429cca + c22e05d commit a3eba26

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

ext/rugged/rugged_index.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,11 @@ static VALUE rb_git_merge_file(int argc, VALUE *argv, VALUE self)
10921092
else
10931093
rugged_exception_check(error);
10941094

1095+
if (ours == NULL)
1096+
rb_raise(rb_eRuntimeError, "The conflict does not have a stage 2 entry");
1097+
else if (theirs == NULL)
1098+
rb_raise(rb_eRuntimeError, "The conflict does not have a stage 3 entry");
1099+
10951100
error = git_merge_file_from_index(&merge_file_result, repo, ancestor, ours, theirs, &opts);
10961101
rugged_exception_check(error);
10971102

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)