Skip to content

Commit 4f22ccb

Browse files
author
John Haley
committed
Add tests for creating an initial commit
1 parent 225cb88 commit 4f22ccb

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

tests/commit/commit.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,91 @@ void test_commit_commit__create_unexisting_update_ref(void)
5151
git_reference_free(ref);
5252
}
5353

54+
void test_commit_commit__create_initial_commit(void)
55+
{
56+
git_oid oid;
57+
git_tree *tree;
58+
git_commit *commit;
59+
git_signature *s;
60+
git_reference *ref;
61+
62+
git_oid_fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
63+
cl_git_pass(git_commit_lookup(&commit, _repo, &oid));
64+
65+
git_oid_fromstr(&oid, "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162");
66+
cl_git_pass(git_tree_lookup(&tree, _repo, &oid));
67+
68+
cl_git_pass(git_signature_now(&s, "alice", "alice@example.com"));
69+
70+
cl_git_fail(git_reference_lookup(&ref, _repo, "refs/heads/foo/bar"));
71+
cl_git_pass(git_commit_create(&oid, _repo, "refs/heads/foo/bar", s, s,
72+
NULL, "initial commit", tree, 0, NULL));
73+
74+
cl_git_pass(git_reference_lookup(&ref, _repo, "refs/heads/foo/bar"));
75+
76+
cl_assert_equal_oid(&oid, git_reference_target(ref));
77+
78+
git_tree_free(tree);
79+
git_commit_free(commit);
80+
git_signature_free(s);
81+
git_reference_free(ref);
82+
}
83+
84+
void test_commit_commit__create_initial_commit_parent_not_current(void)
85+
{
86+
git_oid oid;
87+
git_tree *tree;
88+
git_commit *commit;
89+
git_signature *s;
90+
git_reference *origRef;
91+
git_reference *origRefTarget;
92+
git_reference *ref;
93+
git_reference *refTarget;
94+
95+
git_oid_fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
96+
cl_git_pass(git_commit_lookup(&commit, _repo, &oid));
97+
98+
git_oid_fromstr(&oid, "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162");
99+
cl_git_pass(git_tree_lookup(&tree, _repo, &oid));
100+
101+
cl_git_pass(git_signature_now(&s, "alice", "alice@example.com"));
102+
103+
cl_git_pass(git_reference_lookup(&origRef, _repo, "HEAD"));
104+
105+
cl_git_fail(git_commit_create(&oid, _repo, "HEAD", s, s,
106+
NULL, "initial commit", tree, 0, NULL));
107+
108+
cl_git_pass(git_reference_lookup(&ref, _repo, "HEAD"));
109+
110+
cl_git_pass(
111+
git_reference_lookup(
112+
&origRefTarget,
113+
_repo,
114+
git_reference_symbolic_target(origRef)
115+
)
116+
);
117+
cl_git_pass(
118+
git_reference_lookup(
119+
&refTarget,
120+
_repo,
121+
git_reference_symbolic_target(ref)
122+
)
123+
);
124+
125+
cl_assert_equal_oid(
126+
git_reference_target(origRefTarget),
127+
git_reference_target(refTarget)
128+
);
129+
130+
git_tree_free(tree);
131+
git_commit_free(commit);
132+
git_signature_free(s);
133+
git_reference_free(origRef);
134+
git_reference_free(origRefTarget);
135+
git_reference_free(ref);
136+
git_reference_free(refTarget);
137+
}
138+
54139
void assert_commit_summary(const char *expected, const char *given)
55140
{
56141
git_commit *dummy;

0 commit comments

Comments
 (0)