]>
Commit | Line | Data |
---|---|---|
731df570 | 1 | #include "clar_libgit2.h" |
2 | #include "refs.h" | |
731df570 | 3 | |
4 | static git_repository *repo; | |
5 | static git_reference *fake_remote; | |
6 | ||
7 | void test_refs_branches_delete__initialize(void) | |
8 | { | |
9 | git_oid id; | |
10 | ||
11 | cl_fixture_sandbox("testrepo.git"); | |
12 | cl_git_pass(git_repository_open(&repo, "testrepo.git")); | |
13 | ||
14 | cl_git_pass(git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")); | |
15 | cl_git_pass(git_reference_create_oid(&fake_remote, repo, "refs/remotes/nulltoken/master", &id, 0)); | |
16 | } | |
17 | ||
18 | void test_refs_branches_delete__cleanup(void) | |
19 | { | |
20 | git_reference_free(fake_remote); | |
21 | git_repository_free(repo); | |
22 | ||
23 | cl_fixture_cleanup("testrepo.git"); | |
24 | } | |
25 | ||
731df570 | 26 | void test_refs_branches_delete__can_not_delete_a_branch_pointed_at_by_HEAD(void) |
27 | { | |
28 | git_reference *head; | |
1c947daa | 29 | git_reference *branch; |
731df570 | 30 | |
31 | /* Ensure HEAD targets the local master branch */ | |
32 | cl_git_pass(git_reference_lookup(&head, repo, GIT_HEAD_FILE)); | |
33 | cl_assert(strcmp("refs/heads/master", git_reference_target(head)) == 0); | |
34 | git_reference_free(head); | |
35 | ||
1c947daa VM |
36 | cl_git_pass(git_branch_lookup(&branch, repo, "master", GIT_BRANCH_LOCAL)); |
37 | cl_git_fail(git_branch_delete(branch)); | |
38 | git_reference_free(branch); | |
731df570 | 39 | } |
40 | ||
0532e7bb | 41 | void test_refs_branches_delete__can_delete_a_branch_even_if_HEAD_is_missing(void) |
731df570 | 42 | { |
43 | git_reference *head; | |
0532e7bb | 44 | git_reference *branch; |
731df570 | 45 | |
46 | cl_git_pass(git_reference_lookup(&head, repo, GIT_HEAD_FILE)); | |
47 | git_reference_delete(head); | |
48 | ||
1c947daa | 49 | cl_git_pass(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_LOCAL)); |
0532e7bb | 50 | cl_git_pass(git_branch_delete(branch)); |
731df570 | 51 | } |
52 | ||
53 | void test_refs_branches_delete__can_delete_a_branch_pointed_at_by_detached_HEAD(void) | |
54 | { | |
1c947daa | 55 | git_reference *master, *head, *branch; |
731df570 | 56 | |
57 | /* Detach HEAD and make it target the commit that "master" points to */ | |
58 | cl_git_pass(git_reference_lookup(&master, repo, "refs/heads/master")); | |
59 | cl_git_pass(git_reference_create_oid(&head, repo, "HEAD", git_reference_oid(master), 1)); | |
60 | git_reference_free(head); | |
61 | git_reference_free(master); | |
62 | ||
1c947daa VM |
63 | cl_git_pass(git_branch_lookup(&branch, repo, "master", GIT_BRANCH_LOCAL)); |
64 | cl_git_pass(git_branch_delete(branch)); | |
731df570 | 65 | } |
66 | ||
67 | void test_refs_branches_delete__can_delete_a_local_branch(void) | |
68 | { | |
1c947daa VM |
69 | git_reference *branch; |
70 | cl_git_pass(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_LOCAL)); | |
71 | cl_git_pass(git_branch_delete(branch)); | |
731df570 | 72 | } |
73 | ||
74 | void test_refs_branches_delete__can_delete_a_remote_branch(void) | |
75 | { | |
1c947daa VM |
76 | git_reference *branch; |
77 | cl_git_pass(git_branch_lookup(&branch, repo, "nulltoken/master", GIT_BRANCH_REMOTE)); | |
78 | cl_git_pass(git_branch_delete(branch)); | |
731df570 | 79 | } |
341a7136 | 80 |