]> git.proxmox.com Git - libgit2.git/blob - tests-clar/refs/branches/move.c
branch: add git_branch_move()
[libgit2.git] / tests-clar / refs / branches / move.c
1 #include "clar_libgit2.h"
2 #include "branch.h"
3
4 static git_repository *repo;
5
6 void test_refs_branches_move__initialize(void)
7 {
8 cl_fixture_sandbox("testrepo.git");
9 cl_git_pass(git_repository_open(&repo, "testrepo.git"));
10 }
11
12 void test_refs_branches_move__cleanup(void)
13 {
14 git_repository_free(repo);
15
16 cl_fixture_cleanup("testrepo.git");
17 }
18
19 #define NEW_BRANCH_NAME "new-branch-on-the-block"
20
21 void test_refs_branches_move__can_move_a_local_branch(void)
22 {
23 cl_git_pass(git_branch_move(repo, "br2", NEW_BRANCH_NAME, 0));
24 }
25
26 void test_refs_branches_move__can_move_a_local_branch_to_a_different_namespace(void)
27 {
28 /* Downward */
29 cl_git_pass(git_branch_move(repo, "br2", "somewhere/" NEW_BRANCH_NAME, 0));
30
31 /* Upward */
32 cl_git_pass(git_branch_move(repo, "somewhere/" NEW_BRANCH_NAME, "br2", 0));
33 }
34
35 void test_refs_branches_move__can_move_a_local_branch_to_a_partially_colliding_namespace(void)
36 {
37 /* Downward */
38 cl_git_pass(git_branch_move(repo, "br2", "br2/" NEW_BRANCH_NAME, 0));
39
40 /* Upward */
41 cl_git_pass(git_branch_move(repo, "br2/" NEW_BRANCH_NAME, "br2", 0));
42 }
43
44 void test_refs_branches_move__can_not_move_a_branch_if_its_destination_name_collide_with_an_existing_one(void)
45 {
46 cl_git_fail(git_branch_move(repo, "br2", "master", 0));
47 }
48
49 void test_refs_branches_move__can_not_move_a_non_existing_branch(void)
50 {
51 cl_git_fail(git_branch_move(repo, "i-am-no-branch", NEW_BRANCH_NAME, 0));
52 }
53
54 void test_refs_branches_move__can_force_move_over_an_existing_branch(void)
55 {
56 cl_git_pass(git_branch_move(repo, "br2", "master", 1));
57 }
58
59 void test_refs_branches_move__can_not_move_a_branch_through_its_canonical_name(void)
60 {
61 cl_git_fail(git_branch_move(repo, "refs/heads/br2", NEW_BRANCH_NAME, 1));
62 }