]> git.proxmox.com Git - libgit2.git/blame - tests-clar/refs/branches/delete.c
Merge pull request #1001 from veeti/build-fixes
[libgit2.git] / tests-clar / refs / branches / delete.c
CommitLineData
731df570 1#include "clar_libgit2.h"
2#include "refs.h"
731df570 3
4static git_repository *repo;
5static git_reference *fake_remote;
6
7void 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
18void 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 26void 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 41void 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));
8b05bea8 50 cl_git_pass(git_branch_delete(branch));
51}
52
53void test_refs_branches_delete__can_delete_a_branch_when_HEAD_is_orphaned(void)
54{
55 git_reference *head;
56 git_reference *branch;
57
58 cl_git_pass(git_reference_create_symbolic(&head, repo, GIT_HEAD_FILE, "refs/heads/hide/and/seek", 1));
59 git_reference_free(head);
60
61 cl_git_pass(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_LOCAL));
0532e7bb 62 cl_git_pass(git_branch_delete(branch));
731df570 63}
64
65void test_refs_branches_delete__can_delete_a_branch_pointed_at_by_detached_HEAD(void)
66{
1c947daa 67 git_reference *master, *head, *branch;
731df570 68
69 /* Detach HEAD and make it target the commit that "master" points to */
70 cl_git_pass(git_reference_lookup(&master, repo, "refs/heads/master"));
71 cl_git_pass(git_reference_create_oid(&head, repo, "HEAD", git_reference_oid(master), 1));
72 git_reference_free(head);
73 git_reference_free(master);
74
1c947daa
VM
75 cl_git_pass(git_branch_lookup(&branch, repo, "master", GIT_BRANCH_LOCAL));
76 cl_git_pass(git_branch_delete(branch));
731df570 77}
78
79void test_refs_branches_delete__can_delete_a_local_branch(void)
80{
1c947daa
VM
81 git_reference *branch;
82 cl_git_pass(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_LOCAL));
83 cl_git_pass(git_branch_delete(branch));
731df570 84}
85
86void test_refs_branches_delete__can_delete_a_remote_branch(void)
87{
1c947daa
VM
88 git_reference *branch;
89 cl_git_pass(git_branch_lookup(&branch, repo, "nulltoken/master", GIT_BRANCH_REMOTE));
90 cl_git_pass(git_branch_delete(branch));
731df570 91}
341a7136 92