Hash :
c0311295
Author :
Date :
2014-04-07T17:32:23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
#include "clar_libgit2.h"
#include "buffer.h"
#include "refs.h"
#include "posix.h"
#include "fileops.h"
static git_repository *_repo;
static git_buf _path;
void test_repo_state__initialize(void)
{
_repo = cl_git_sandbox_init("testrepo.git");
}
void test_repo_state__cleanup(void)
{
cl_git_sandbox_cleanup();
git_buf_free(&_path);
}
static void setup_simple_state(const char *filename)
{
cl_git_pass(git_buf_joinpath(&_path, git_repository_path(_repo), filename));
git_futils_mkpath2file(git_buf_cstr(&_path), 0777);
cl_git_mkfile(git_buf_cstr(&_path), "dummy");
}
static void assert_repo_state(git_repository_state_t state)
{
cl_assert_equal_i(state, git_repository_state(_repo));
}
void test_repo_state__none_with_HEAD_attached(void)
{
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__none_with_HEAD_detached(void)
{
cl_git_pass(git_repository_detach_head(_repo, NULL, NULL));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__merge(void)
{
setup_simple_state(GIT_MERGE_HEAD_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_MERGE);
cl_git_pass(git_repository_state_cleanup(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__revert(void)
{
setup_simple_state(GIT_REVERT_HEAD_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_REVERT);
cl_git_pass(git_repository_state_cleanup(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__cherry_pick(void)
{
setup_simple_state(GIT_CHERRY_PICK_HEAD_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_CHERRY_PICK);
cl_git_pass(git_repository_state_cleanup(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__bisect(void)
{
setup_simple_state(GIT_BISECT_LOG_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_BISECT);
cl_git_pass(git_repository_state_cleanup(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__rebase_interactive(void)
{
setup_simple_state(GIT_REBASE_MERGE_INTERACTIVE_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_REBASE_INTERACTIVE);
cl_git_pass(git_repository_state_cleanup(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__rebase_merge(void)
{
setup_simple_state(GIT_REBASE_MERGE_DIR "whatever");
assert_repo_state(GIT_REPOSITORY_STATE_REBASE_MERGE);
cl_git_pass(git_repository_state_cleanup(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__rebase(void)
{
setup_simple_state(GIT_REBASE_APPLY_REBASING_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_REBASE);
cl_git_pass(git_repository_state_cleanup(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__apply_mailbox(void)
{
setup_simple_state(GIT_REBASE_APPLY_APPLYING_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_APPLY_MAILBOX);
cl_git_pass(git_repository_state_cleanup(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__apply_mailbox_or_rebase(void)
{
setup_simple_state(GIT_REBASE_APPLY_DIR "whatever");
assert_repo_state(GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE);
cl_git_pass(git_repository_state_cleanup(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}