]>
git.proxmox.com Git - libgit2.git/blob - tests/graph/ahead_behind.c
77d7768afe416e7211220e3966398a8ad4f5fbc8
1 #include "clar_libgit2.h"
3 static git_repository
*_repo
;
4 static git_commit
*commit
;
8 void test_graph_ahead_behind__initialize(void)
11 cl_git_pass(git_repository_open(&_repo
, cl_fixture("testrepo.git")));
13 cl_git_pass(git_oid_fromstr(&oid
, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
14 cl_git_pass(git_commit_lookup(&commit
, _repo
, &oid
));
17 void test_graph_ahead_behind__cleanup(void)
19 git_commit_free(commit
);
22 git_repository_free(_repo
);
26 void test_graph_ahead_behind__returns_correct_result(void)
32 cl_git_pass(git_oid_fromstr(&oid
, "e90810b8df3e80c413d903f631643c716887138d"));
33 cl_git_pass(git_oid_fromstr(&oid2
, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
35 cl_git_pass(git_graph_ahead_behind(&ahead
, &behind
, _repo
, &oid
, &oid2
));
36 cl_assert_equal_sz(2, ahead
);
37 cl_assert_equal_sz(6, behind
);
39 cl_git_pass(git_graph_ahead_behind(&ahead
, &behind
, _repo
, git_commit_id(commit
), git_commit_id(commit
)));
40 cl_assert_equal_sz(ahead
, behind
);
41 cl_git_pass(git_commit_nth_gen_ancestor(&other
, commit
, 1));
43 cl_git_pass(git_graph_ahead_behind(&ahead
, &behind
, _repo
, git_commit_id(commit
), git_commit_id(other
)));
44 cl_assert_equal_sz(ahead
, behind
+ 2);
45 cl_git_pass(git_graph_ahead_behind(&ahead
, &behind
, _repo
, git_commit_id(other
), git_commit_id(commit
)));
46 cl_assert_equal_sz(ahead
+ 2, behind
);
48 git_commit_free(other
);
50 cl_git_pass(git_commit_nth_gen_ancestor(&other
, commit
, 3));
52 cl_git_pass(git_graph_ahead_behind(&ahead
, &behind
, _repo
, git_commit_id(commit
), git_commit_id(other
)));
53 cl_assert_equal_sz(ahead
, behind
+ 4);
54 cl_git_pass(git_graph_ahead_behind(&ahead
, &behind
, _repo
, git_commit_id(other
), git_commit_id(commit
)));
55 cl_assert_equal_sz(ahead
+ 4, behind
);
57 git_commit_free(other
);