diff options
| author | Vicent Martà <vicent@github.com> | 2012-10-24 18:33:02 -0700 |
|---|---|---|
| committer | Vicent Martà <vicent@github.com> | 2012-10-24 18:33:02 -0700 |
| commit | 5edb846e03961cac06d1aab4cb5e2329936837f1 (patch) | |
| tree | 886a12f4ff2390f21f9fb3c6e9c15a1781875521 /tests-clar | |
| parent | 6f6b0c013c6eff2aca2a7ada1027044f2e20f578 (diff) | |
| parent | 03bdb2addd02948e0e42b509e5c26c6eb5e7e1de (diff) | |
| download | libgit2-5edb846e03961cac06d1aab4cb5e2329936837f1.tar.gz | |
Merge pull request #1013 from ethomson/reset_merge
reset changes for merge
Diffstat (limited to 'tests-clar')
| -rw-r--r-- | tests-clar/repo/state.c | 47 | ||||
| -rw-r--r-- | tests-clar/reset/hard.c | 35 | ||||
| -rw-r--r-- | tests-clar/reset/soft.c | 15 |
3 files changed, 97 insertions, 0 deletions
diff --git a/tests-clar/repo/state.c b/tests-clar/repo/state.c new file mode 100644 index 000000000..1ee84374c --- /dev/null +++ b/tests-clar/repo/state.c @@ -0,0 +1,47 @@ +#include "clar_libgit2.h" +#include "buffer.h" +#include "refs.h" +#include "posix.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); +} + +void test_repo_state__none(void) +{ + /* The repo should be at its default state */ + cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(_repo)); +} + +void test_repo_state__merge(void) +{ + + /* Then it should recognise that .git/MERGE_HEAD and friends mean their respective states */ + cl_git_pass(git_buf_joinpath(&_path, git_repository_path(_repo), GIT_MERGE_HEAD_FILE)); + cl_git_mkfile(git_buf_cstr(&_path), "dummy"); + cl_assert_equal_i(GIT_REPOSITORY_STATE_MERGE, git_repository_state(_repo)); +} + +void test_repo_state__revert(void) +{ + cl_git_pass(git_buf_joinpath(&_path, git_repository_path(_repo), GIT_REVERT_HEAD_FILE)); + cl_git_mkfile(git_buf_cstr(&_path), "dummy"); + cl_assert_equal_i(GIT_REPOSITORY_STATE_REVERT, git_repository_state(_repo)); +} + +void test_repo_state__cherry_pick(void) +{ + cl_git_pass(git_buf_joinpath(&_path, git_repository_path(_repo), GIT_CHERRY_PICK_HEAD_FILE)); + cl_git_mkfile(git_buf_cstr(&_path), "dummy"); + cl_assert_equal_i(GIT_REPOSITORY_STATE_CHERRY_PICK, git_repository_state(_repo)); +} diff --git a/tests-clar/reset/hard.c b/tests-clar/reset/hard.c index fdab9c536..c3f041817 100644 --- a/tests-clar/reset/hard.c +++ b/tests-clar/reset/hard.c @@ -58,3 +58,38 @@ void test_reset_hard__cannot_reset_in_a_bare_repository(void) git_repository_free(bare); } + +void test_reset_hard__cleans_up_merge(void) +{ + git_buf merge_head_path = GIT_BUF_INIT, + merge_msg_path = GIT_BUF_INIT, + merge_mode_path = GIT_BUF_INIT, + orig_head_path = GIT_BUF_INIT; + + cl_git_pass(git_buf_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD")); + cl_git_mkfile(git_buf_cstr(&merge_head_path), "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef\n"); + + cl_git_pass(git_buf_joinpath(&merge_msg_path, git_repository_path(repo), "MERGE_MSG")); + cl_git_mkfile(git_buf_cstr(&merge_head_path), "Merge commit 0017bd4ab1ec30440b17bae1680cff124ab5f1f6\n"); + + cl_git_pass(git_buf_joinpath(&merge_msg_path, git_repository_path(repo), "MERGE_MODE")); + cl_git_mkfile(git_buf_cstr(&merge_head_path), ""); + + cl_git_pass(git_buf_joinpath(&orig_head_path, git_repository_path(repo), "ORIG_HEAD")); + cl_git_mkfile(git_buf_cstr(&orig_head_path), "0017bd4ab1ec30440b17bae1680cff124ab5f1f6"); + + retrieve_target_from_oid(&target, repo, "0017bd4ab1ec30440b17bae1680cff124ab5f1f6"); + cl_git_pass(git_reset(repo, target, GIT_RESET_HARD)); + + cl_assert(!git_path_exists(git_buf_cstr(&merge_head_path))); + cl_assert(!git_path_exists(git_buf_cstr(&merge_msg_path))); + cl_assert(!git_path_exists(git_buf_cstr(&merge_mode_path))); + + cl_assert(git_path_exists(git_buf_cstr(&orig_head_path))); + cl_git_pass(p_unlink(git_buf_cstr(&orig_head_path))); + + git_buf_free(&merge_head_path); + git_buf_free(&merge_msg_path); + git_buf_free(&merge_mode_path); + git_buf_free(&orig_head_path); +} diff --git a/tests-clar/reset/soft.c b/tests-clar/reset/soft.c index 1872baf3b..fa206455d 100644 --- a/tests-clar/reset/soft.c +++ b/tests-clar/reset/soft.c @@ -1,5 +1,7 @@ #include "clar_libgit2.h" +#include "posix.h" #include "reset_helpers.h" +#include "path.h" #include "repo/repo_helpers.h" static git_repository *repo; @@ -110,3 +112,16 @@ void test_reset_soft__resetting_against_an_orphaned_head_repo_makes_the_head_no_ git_reference_free(head); } + +void test_reset_soft__fails_when_merging(void) +{ + git_buf merge_head_path = GIT_BUF_INIT; + + cl_git_pass(git_buf_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD")); + cl_git_mkfile(git_buf_cstr(&merge_head_path), "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef\n"); + + retrieve_target_from_oid(&target, repo, KNOWN_COMMIT_IN_BARE_REPO); + + cl_assert_equal_i(GIT_EUNMERGED, git_reset(repo, target, GIT_RESET_SOFT)); + cl_git_pass(p_unlink(git_buf_cstr(&merge_head_path))); +} |
