File: ahead_behind.c

package info (click to toggle)
libgit2 1.1.0%2Bdfsg.1-4%2Bdeb11u2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 53,324 kB
  • sloc: ansic: 173,567; sh: 562; python: 351; php: 65; makefile: 50
file content (58 lines) | stat: -rw-r--r-- 1,867 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "clar_libgit2.h"

static git_repository *_repo;
static git_commit *commit;
static size_t ahead;
static size_t behind;

void test_graph_ahead_behind__initialize(void)
{
	git_oid oid;
	cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git")));

	cl_git_pass(git_oid_fromstr(&oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
	cl_git_pass(git_commit_lookup(&commit, _repo, &oid));
}

void test_graph_ahead_behind__cleanup(void)
{
	git_commit_free(commit);
	commit = NULL;

	git_repository_free(_repo);
	_repo = NULL;
}

void test_graph_ahead_behind__returns_correct_result(void)
{	
	git_oid oid;
	git_oid oid2;
	git_commit *other;

	cl_git_pass(git_oid_fromstr(&oid, "e90810b8df3e80c413d903f631643c716887138d"));
	cl_git_pass(git_oid_fromstr(&oid2, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
	
	cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, &oid, &oid2));
	cl_assert_equal_sz(2, ahead);
	cl_assert_equal_sz(6, behind);

	cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, git_commit_id(commit), git_commit_id(commit)));
	cl_assert_equal_sz(ahead, behind);
	cl_git_pass(git_commit_nth_gen_ancestor(&other, commit, 1));

	cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, git_commit_id(commit), git_commit_id(other)));
	cl_assert_equal_sz(ahead, behind + 2);
	cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, git_commit_id(other), git_commit_id(commit)));
	cl_assert_equal_sz(ahead + 2, behind);

	git_commit_free(other);

	cl_git_pass(git_commit_nth_gen_ancestor(&other, commit, 3));

	cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, git_commit_id(commit), git_commit_id(other)));
	cl_assert_equal_sz(ahead, behind + 4);
	cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, git_commit_id(other), git_commit_id(commit)));
	cl_assert_equal_sz(ahead + 4, behind);

	git_commit_free(other);
}