Skip to content

Commit 5785ae9

Browse files
author
John Haley
committed
Fix initial commit test
`test_commit_commit__create_initial_commit_parent_not_current` was not correctly testing that `HEAD` was not changed. Now we grab the oid that it was pointing to before the call to `git_commit_create` and the oid that it's pointing to afterwards and compare those.
1 parent 4f22ccb commit 5785ae9

File tree

1 file changed

+5
-30
lines changed

1 file changed

+5
-30
lines changed

tests/commit/commit.c

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,10 @@ void test_commit_commit__create_initial_commit(void)
8484
void test_commit_commit__create_initial_commit_parent_not_current(void)
8585
{
8686
git_oid oid;
87+
git_oid original_oid;
8788
git_tree *tree;
8889
git_commit *commit;
8990
git_signature *s;
90-
git_reference *origRef;
91-
git_reference *origRefTarget;
92-
git_reference *ref;
93-
git_reference *refTarget;
9491

9592
git_oid_fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
9693
cl_git_pass(git_commit_lookup(&commit, _repo, &oid));
@@ -100,40 +97,18 @@ void test_commit_commit__create_initial_commit_parent_not_current(void)
10097

10198
cl_git_pass(git_signature_now(&s, "alice", "alice@example.com"));
10299

103-
cl_git_pass(git_reference_lookup(&origRef, _repo, "HEAD"));
100+
cl_git_pass(git_reference_name_to_id(&original_oid, _repo, "HEAD"));
104101

105102
cl_git_fail(git_commit_create(&oid, _repo, "HEAD", s, s,
106103
NULL, "initial commit", tree, 0, NULL));
107104

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-
);
105+
cl_git_pass(git_reference_name_to_id(&oid, _repo, "HEAD"));
106+
107+
cl_assert_equal_oid(&oid, &original_oid);
129108

130109
git_tree_free(tree);
131110
git_commit_free(commit);
132111
git_signature_free(s);
133-
git_reference_free(origRef);
134-
git_reference_free(origRefTarget);
135-
git_reference_free(ref);
136-
git_reference_free(refTarget);
137112
}
138113

139114
void assert_commit_summary(const char *expected, const char *given)

0 commit comments

Comments
 (0)