Skip to content

Commit 397cf1a

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 397cf1a

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

tests/refs/reflog/reflog.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "git2/reflog.h"
55
#include "reflog.h"
66

7-
7+
static const char *merge_reflog_message = "commit (merge): Merge commit";
88
static const char *new_ref = "refs/heads/test-reflog";
99
static const char *current_master_tip = "a65fedf39aefe402d3bb6e24df4d4f5fe4547750";
1010
#define commit_msg "commit: bla bla"
@@ -448,3 +448,45 @@ void test_refs_reflog_reflog__logallrefupdates_nonbare_set_false(void)
448448

449449
assert_no_reflog_update();
450450
}
451+
452+
void test_refs_reflog_reflog__show_merge_for_merge_commits(void)
453+
{
454+
git_oid b1_oid;
455+
git_oid b2_oid;
456+
git_oid merge_commit_oid;
457+
git_commit *b1_commit;
458+
git_commit *b2_commit;
459+
git_signature *s;
460+
git_commit *parent_commits[2];
461+
git_tree *tree;
462+
git_reflog *log;
463+
const git_reflog_entry *entry;
464+
465+
cl_git_pass(git_signature_now(&s, "alice", "alice@example.com"));
466+
467+
cl_git_pass(git_reference_name_to_id(&b1_oid, g_repo, "HEAD"));
468+
cl_git_pass(git_reference_name_to_id(&b2_oid, g_repo, "refs/heads/test"));
469+
470+
cl_git_pass(git_commit_lookup(&b1_commit, g_repo, &b1_oid));
471+
cl_git_pass(git_commit_lookup(&b2_commit, g_repo, &b2_oid));
472+
473+
parent_commits[0] = b1_commit;
474+
parent_commits[1] = b2_commit;
475+
476+
cl_git_pass(git_commit_tree(&tree, b1_commit));
477+
478+
cl_git_pass(git_commit_create(&merge_commit_oid,
479+
g_repo, "HEAD", s, s, NULL,
480+
"Merge commit", tree,
481+
2, (const struct git_commit **) parent_commits));
482+
483+
cl_git_pass(git_reflog_read(&log, g_repo, "HEAD"));
484+
entry = git_reflog_entry_byindex(log, 0);
485+
cl_assert_equal_s(merge_reflog_message, git_reflog_entry_message(entry));
486+
487+
git_reflog_free(log);
488+
git_tree_free(tree);
489+
git_commit_free(b1_commit);
490+
git_commit_free(b2_commit);
491+
git_signature_free(s);
492+
}

0 commit comments

Comments
 (0)