move.c 1.59 KB
Newer Older
1
#include "clar_libgit2.h"
2
#include "refs.h"
3 4

static git_repository *repo;
5
static git_reference *ref;
6 7 8

void test_refs_branches_move__initialize(void)
{
9 10 11
	repo = cl_git_sandbox_init("testrepo.git");

	cl_git_pass(git_reference_lookup(&ref, repo, "refs/heads/br2"));
12 13 14 15
}

void test_refs_branches_move__cleanup(void)
{
16 17
	git_reference_free(ref);
	cl_git_sandbox_cleanup();
18 19 20 21 22 23
}

#define NEW_BRANCH_NAME "new-branch-on-the-block"

void test_refs_branches_move__can_move_a_local_branch(void)
{
24 25
	cl_git_pass(git_branch_move(ref, NEW_BRANCH_NAME, 0));
	cl_assert_equal_s(GIT_REFS_HEADS_DIR NEW_BRANCH_NAME, git_reference_name(ref));
26 27 28 29 30
}

void test_refs_branches_move__can_move_a_local_branch_to_a_different_namespace(void)
{
	/* Downward */
31
	cl_git_pass(git_branch_move(ref, "somewhere/" NEW_BRANCH_NAME, 0));
32 33

	/* Upward */
34
	cl_git_pass(git_branch_move(ref, "br2", 0));
35 36 37 38 39
}

void test_refs_branches_move__can_move_a_local_branch_to_a_partially_colliding_namespace(void)
{
	/* Downward */
40
	cl_git_pass(git_branch_move(ref, "br2/" NEW_BRANCH_NAME, 0));
41 42

	/* Upward */
43
	cl_git_pass(git_branch_move(ref, "br2", 0));
44 45 46 47
}

void test_refs_branches_move__can_not_move_a_branch_if_its_destination_name_collide_with_an_existing_one(void)
{
48
	cl_git_fail(git_branch_move(ref, "master", 0));
49 50
}

51
void test_refs_branches_move__can_not_move_a_non_branch(void)
52
{
53
	git_reference *tag;
54

55 56
	cl_git_pass(git_reference_lookup(&tag, repo, "refs/tags/e90810b"));
	cl_git_fail(git_branch_move(tag, NEW_BRANCH_NAME, 0));
57

58
	git_reference_free(tag);
59
}
60

61
void test_refs_branches_move__can_force_move_over_an_existing_branch(void)
62
{
63
	cl_git_pass(git_branch_move(ref, "master", 1));
64
}