Skip to content

Commit f6f7c8d

Browse files
committed
merge: Add fail_on_conflict
1 parent 00c863c commit f6f7c8d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

ext/rugged/rugged_repo.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ static VALUE rb_git_repo_merge_commits(int argc, VALUE *argv, VALUE self)
846846
git_index *index;
847847
git_repository *repo;
848848
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
849+
int error;
849850

850851
rb_scan_args(argc, argv, "20:", &rb_our_commit, &rb_their_commit, &rb_options);
851852

@@ -874,7 +875,11 @@ static VALUE rb_git_repo_merge_commits(int argc, VALUE *argv, VALUE self)
874875
Data_Get_Struct(rb_our_commit, git_commit, our_commit);
875876
Data_Get_Struct(rb_their_commit, git_commit, their_commit);
876877

877-
rugged_exception_check(git_merge_commits(&index, repo, our_commit, their_commit, &opts));
878+
error = git_merge_commits(&index, repo, our_commit, their_commit, &opts);
879+
if (error == GIT_EMERGECONFLICT)
880+
return Qnil;
881+
882+
rugged_exception_check(error);
878883

879884
return rugged_index_new(rb_cRuggedIndex, self, index);
880885
}

ext/rugged/rugged_tree.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,10 @@ void rugged_parse_merge_options(git_merge_options *opts, VALUE rb_options)
616616
if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("renames")))) {
617617
opts->tree_flags |= GIT_MERGE_TREE_FIND_RENAMES;
618618
}
619+
620+
if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("fail_on_conflict")))) {
621+
opts->tree_flags |= GIT_MERGE_TREE_FAIL_ON_CONFLICT;
622+
}
619623
}
620624
}
621625

@@ -682,6 +686,9 @@ static VALUE rb_git_tree_merge(int argc, VALUE *argv, VALUE self)
682686
ancestor_tree = NULL;
683687

684688
error = git_merge_trees(&index, repo, ancestor_tree, tree, other_tree, &opts);
689+
if (error == GIT_EMERGECONFLICT)
690+
return Qnil;
691+
685692
rugged_exception_check(error);
686693

687694
return rugged_index_new(rb_cRuggedIndex, rb_repo, index);

0 commit comments

Comments
 (0)