]> git.proxmox.com Git - libgit2.git/blob - tests/refs/branches/lookup.c
95d49a4b35c6e30fac06c6b57a9f21635a125042
[libgit2.git] / tests / refs / branches / lookup.c
1 #include "clar_libgit2.h"
2 #include "refs.h"
3
4 static git_repository *repo;
5 static git_reference *branch;
6
7 void test_refs_branches_lookup__initialize(void)
8 {
9 cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
10
11 branch = NULL;
12 }
13
14 void test_refs_branches_lookup__cleanup(void)
15 {
16 git_reference_free(branch);
17 branch = NULL;
18
19 git_repository_free(repo);
20 repo = NULL;
21 }
22
23 void test_refs_branches_lookup__can_retrieve_a_local_branch(void)
24 {
25 cl_git_pass(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_LOCAL));
26 }
27
28 void test_refs_branches_lookup__can_retrieve_a_remote_tracking_branch(void)
29 {
30 cl_git_pass(git_branch_lookup(&branch, repo, "test/master", GIT_BRANCH_REMOTE));
31 }
32
33 void test_refs_branches_lookup__trying_to_retrieve_an_unknown_branch_returns_ENOTFOUND(void)
34 {
35 cl_assert_equal_i(GIT_ENOTFOUND, git_branch_lookup(&branch, repo, "where/are/you", GIT_BRANCH_LOCAL));
36 cl_assert_equal_i(GIT_ENOTFOUND, git_branch_lookup(&branch, repo, "over/here", GIT_BRANCH_REMOTE));
37 }
38
39 void test_refs_branches_lookup__trying_to_retrieve_a_branch_with_an_invalid_name_returns_EINVALIDSPEC(void)
40 {
41 cl_assert_equal_i(GIT_EINVALIDSPEC,
42 git_branch_lookup(&branch, repo, "are/you/inv@{id", GIT_BRANCH_LOCAL));
43 cl_assert_equal_i(GIT_EINVALIDSPEC,
44 git_branch_lookup(&branch, repo, "yes/i am", GIT_BRANCH_REMOTE));
45 }