Skip to content

Commit 7ea61c2

Browse files
committed
Add test for inclusion of (merge) in reflog
This test ensures that the string '(merge)' is included in the reflog when a merge commit is made.
1 parent 1255a9a commit 7ea61c2

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

tests/commit/merge.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include "clar_libgit2.h"
2+
#include "commit.h"
3+
#include "git2/commit.h"
4+
#include "../merge/merge_helpers.h"
5+
6+
static const char *merge_reflog_message = "commit (merge): Merge commit";
7+
8+
static git_repository *_repo;
9+
10+
void test_commit_merge__initialize(void)
11+
{
12+
_repo = cl_git_sandbox_init("merge-recursive");
13+
}
14+
15+
void test_commit_merge__cleanup(void)
16+
{
17+
cl_git_sandbox_cleanup();
18+
}
19+
20+
void test_commit_merge__merge_commit_shows_in_reflog(void)
21+
{
22+
git_index *index;
23+
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
24+
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
25+
git_oid b1_oid;
26+
git_oid b2_oid;
27+
git_oid tree_oid;
28+
git_oid merge_commit_oid;
29+
git_commit *b1_commit;
30+
git_commit *b2_commit;
31+
git_signature *s;
32+
git_commit *parent_commits[2];
33+
git_tree *tree;
34+
git_reflog *log;
35+
const git_reflog_entry *entry;
36+
37+
cl_git_pass(git_signature_now(&s, "alice", "alice@example.com"));
38+
39+
cl_git_pass(git_reference_name_to_id(&b1_oid, _repo, "refs/heads/branchB-1"));
40+
cl_git_pass(git_reference_name_to_id(&b2_oid, _repo, "refs/heads/branchB-2"));
41+
42+
cl_git_pass(git_commit_lookup(&b1_commit, _repo, &b1_oid));
43+
cl_git_pass(git_commit_lookup(&b2_commit, _repo, &b2_oid));
44+
45+
parent_commits[0] = b1_commit;
46+
parent_commits[1] = b2_commit;
47+
48+
cl_git_pass(merge_branches(_repo,
49+
"refs/heads/branchB-1", "refs/heads/branchB-2",
50+
&merge_opts, &checkout_opts));
51+
52+
cl_git_pass(git_repository_index(&index, _repo));
53+
cl_git_pass(git_index_read(index, 1));
54+
cl_assert_(!git_index_has_conflicts(index), "Index has conflicts!");
55+
cl_git_pass(git_index_write_tree(&tree_oid, index));
56+
cl_git_pass(git_tree_lookup(&tree, _repo, &tree_oid));
57+
58+
cl_git_pass(git_commit_create(&merge_commit_oid,
59+
_repo, "refs/heads/branchB-1", s, s, NULL,
60+
"Merge commit", tree,
61+
2, (const struct git_commit **) parent_commits));
62+
63+
cl_git_pass(git_reflog_read(&log, _repo, "refs/heads/branchB-1"));
64+
entry = git_reflog_entry_byindex(log, 0);
65+
cl_assert_equal_s(merge_reflog_message, git_reflog_entry_message(entry));
66+
}

0 commit comments

Comments
 (0)