Method: Rugged::Repository#merge_analysis
- Defined in:
- ext/rugged/rugged_repo.c
#merge_analysis(their_commit) ⇒ Array
Analyzes the given commit and determines the opportunities for merging it into the repository’s HEAD. Returns an Array containing a combination of the following symbols:
- :normal
-
A “normal” merge is possible, both HEAD and the given commit have diverged from their common ancestor. The divergent commits must be merged.
- :up_to_date
-
The given commit is reachable from HEAD, meaning HEAD is up-to-date and no merge needs to be performed.
- :fastforward
-
The given commit is a fast-forward from HEAD and no merge needs to be performed. HEAD can simply be set to the given commit.
- :unborn
-
The HEAD of the current repository is “unborn” and does not point to a valid commit. No merge can be performed, but the caller may wish to simply set HEAD to the given commit.
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 |
# File 'ext/rugged/rugged_repo.c', line 889
static VALUE rb_git_repo_merge_analysis(int argc, VALUE *argv, VALUE self)
{
int error;
git_repository *repo;
git_commit *their_commit;
git_annotated_commit *annotated_commit;
git_merge_analysis_t analysis;
git_merge_preference_t preference;
VALUE rb_their_commit, result;
rb_scan_args(argc, argv, "10", &rb_their_commit);
Data_Get_Struct(self, git_repository, repo);
if (TYPE(rb_their_commit) == T_STRING) {
rb_their_commit = rugged_object_rev_parse(self, rb_their_commit, 1);
}
if (!rb_obj_is_kind_of(rb_their_commit, rb_cRuggedCommit)) {
rb_raise(rb_eArgError, "Expected a Rugged::Commit.");
}
TypedData_Get_Struct(rb_their_commit, git_commit, &rugged_object_type, their_commit);
error = git_annotated_commit_lookup(&annotated_commit, repo, git_commit_id(their_commit));
rugged_exception_check(error);
error = git_merge_analysis(&analysis, &preference, repo,
/* hack as we currently only do one commit */
(const git_annotated_commit **) &annotated_commit, 1);
git_annotated_commit_free(annotated_commit);
rugged_exception_check(error);
result = rb_ary_new();
if (analysis & GIT_MERGE_ANALYSIS_NORMAL)
rb_ary_push(result, CSTR2SYM("normal"));
if (analysis & GIT_MERGE_ANALYSIS_UP_TO_DATE)
rb_ary_push(result, CSTR2SYM("up_to_date"));
if (analysis & GIT_MERGE_ANALYSIS_FASTFORWARD)
rb_ary_push(result, CSTR2SYM("fastforward"));
if (analysis & GIT_MERGE_ANALYSIS_UNBORN)
rb_ary_push(result, CSTR2SYM("unborn"));
return result;
}
|