diff options
Diffstat (limited to 'tests-clar')
| -rw-r--r-- | tests-clar/checkout/crlf.c | 5 | ||||
| -rw-r--r-- | tests-clar/clone/empty.c | 2 | ||||
| -rw-r--r-- | tests-clar/diff/patch.c | 6 | ||||
| -rw-r--r-- | tests-clar/refs/branches/trackingname.c | 2 | ||||
| -rw-r--r-- | tests-clar/reset/default.c | 180 |
5 files changed, 185 insertions, 10 deletions
diff --git a/tests-clar/checkout/crlf.c b/tests-clar/checkout/crlf.c index 856d32bd1..38c0080d3 100644 --- a/tests-clar/checkout/crlf.c +++ b/tests-clar/checkout/crlf.c @@ -16,12 +16,7 @@ static git_repository *g_repo; void test_checkout_crlf__initialize(void) { - git_tree *tree; - g_repo = cl_git_sandbox_init("crlf"); - - cl_git_pass(git_repository_head_tree(&tree, g_repo)); - git_tree_free(tree); } void test_checkout_crlf__cleanup(void) diff --git a/tests-clar/clone/empty.c b/tests-clar/clone/empty.c index 4e53557a0..e611bc24e 100644 --- a/tests-clar/clone/empty.c +++ b/tests-clar/clone/empty.c @@ -46,7 +46,7 @@ void test_clone_empty__can_clone_an_empty_local_repo_barely(void) cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&ref, g_repo_cloned, local_name)); /* ...one can still retrieve the name of the remote tracking reference */ - cl_assert_equal_i(strlen("refs/remotes/origin/master") + 1, + cl_assert_equal_i((int)strlen("refs/remotes/origin/master") + 1U, git_branch_tracking_name(tracking_name, 1024, g_repo_cloned, local_name)); } diff --git a/tests-clar/diff/patch.c b/tests-clar/diff/patch.c index affa761de..18e90f92d 100644 --- a/tests-clar/diff/patch.c +++ b/tests-clar/diff/patch.c @@ -251,13 +251,13 @@ static void check_single_patch_stats( cl_git_pass(git_diff_get_patch(&patch, &delta, diff, 0)); cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status); - cl_assert_equal_i(hunks, (int)git_diff_patch_num_hunks(patch)); + cl_assert_equal_sz(hunks, git_diff_patch_num_hunks(patch)); cl_git_pass( git_diff_patch_line_stats(NULL, &actual_adds, &actual_dels, patch)); - cl_assert_equal_i(adds, actual_adds); - cl_assert_equal_i(dels, actual_dels); + cl_assert_equal_sz(adds, actual_adds); + cl_assert_equal_sz(dels, actual_dels); git_diff_patch_free(patch); git_diff_list_free(diff); diff --git a/tests-clar/refs/branches/trackingname.c b/tests-clar/refs/branches/trackingname.c index ea9058357..5aee33343 100644 --- a/tests-clar/refs/branches/trackingname.c +++ b/tests-clar/refs/branches/trackingname.c @@ -37,6 +37,6 @@ void test_refs_branches_trackingname__can_retrieve_the_local_tracking_reference_ void test_refs_branches_trackingname__can_return_the_size_of_thelocal_tracking_reference_name_of_a_local_branch(void) { - cl_assert_equal_i(strlen("refs/heads/master") + 1, + cl_assert_equal_i((int)strlen("refs/heads/master") + 1, git_branch_tracking_name(NULL, 0, repo, "refs/heads/track-local")); } diff --git a/tests-clar/reset/default.c b/tests-clar/reset/default.c new file mode 100644 index 000000000..506d971ff --- /dev/null +++ b/tests-clar/reset/default.c @@ -0,0 +1,180 @@ +#include "clar_libgit2.h" +#include "posix.h" +#include "reset_helpers.h" +#include "path.h" + +static git_repository *_repo; +static git_object *_target; +static git_strarray _pathspecs; +static git_index *_index; + +static void initialize(const char *repo_name) +{ + _repo = cl_git_sandbox_init(repo_name); + cl_git_pass(git_repository_index(&_index, _repo)); + + _target = NULL; + + _pathspecs.strings = NULL; + _pathspecs.count = 0; +} + +void test_reset_default__initialize(void) +{ + initialize("status"); +} + +void test_reset_default__cleanup(void) +{ + git_object_free(_target); + _target = NULL; + + git_index_free(_index); + _index = NULL; + + cl_git_sandbox_cleanup(); +} + +static void assert_content_in_index( + git_strarray *pathspecs, + bool should_exist, + git_strarray *expected_shas) +{ + size_t i, pos; + int error; + + for (i = 0; i < pathspecs->count; i++) { + error = git_index_find(&pos, _index, pathspecs->strings[i]); + + if (should_exist) { + const git_index_entry *entry; + + cl_assert(error != GIT_ENOTFOUND); + + entry = git_index_get_byindex(_index, pos); + cl_assert(entry != NULL); + + if (!expected_shas) + continue; + + cl_git_pass(git_oid_streq(&entry->oid, expected_shas->strings[i])); + } else + cl_assert_equal_i(should_exist, error != GIT_ENOTFOUND); + } +} + +void test_reset_default__resetting_filepaths_against_a_null_target_removes_them_from_the_index(void) +{ + char *paths[] = { "staged_changes", "staged_new_file" }; + + _pathspecs.strings = paths; + _pathspecs.count = 2; + + assert_content_in_index(&_pathspecs, true, NULL); + + cl_git_pass(git_reset_default(_repo, NULL, &_pathspecs)); + + assert_content_in_index(&_pathspecs, false, NULL); +} + +/* + * $ git ls-files --cached -s --abbrev=7 -- "staged*" + * 100644 55d316c 0 staged_changes + * 100644 a6be623 0 staged_changes_file_deleted + * ... + * + * $ git reset 0017bd4 -- staged_changes staged_changes_file_deleted + * Unstaged changes after reset: + * ... + * + * $ git ls-files --cached -s --abbrev=7 -- "staged*" + * 100644 32504b7 0 staged_changes + * 100644 061d42a 0 staged_changes_file_deleted + * ... + */ +void test_reset_default__resetting_filepaths_replaces_their_corresponding_index_entries(void) +{ + git_strarray before, after; + + char *paths[] = { "staged_changes", "staged_changes_file_deleted" }; + char *before_shas[] = { "55d316c9ba708999f1918e9677d01dfcae69c6b9", + "a6be623522ce87a1d862128ac42672604f7b468b" }; + char *after_shas[] = { "32504b727382542f9f089e24fddac5e78533e96c", + "061d42a44cacde5726057b67558821d95db96f19" }; + + _pathspecs.strings = paths; + _pathspecs.count = 2; + before.strings = before_shas; + before.count = 2; + after.strings = after_shas; + after.count = 2; + + cl_git_pass(git_revparse_single(&_target, _repo, "0017bd4")); + assert_content_in_index(&_pathspecs, true, &before); + + cl_git_pass(git_reset_default(_repo, _target, &_pathspecs)); + + assert_content_in_index(&_pathspecs, true, &after); +} + +/* + * $ git ls-files --cached -s --abbrev=7 -- conflicts-one.txt + * 100644 1f85ca5 1 conflicts-one.txt + * 100644 6aea5f2 2 conflicts-one.txt + * 100644 516bd85 3 conflicts-one.txt + * + * $ git reset 9a05ccb -- conflicts-one.txt + * Unstaged changes after reset: + * ... + * + * $ git ls-files --cached -s --abbrev=7 -- conflicts-one.txt + * 100644 1f85ca5 0 conflicts-one.txt + * + */ +void test_reset_default__resetting_filepaths_clears_previous_conflicts(void) +{ + git_index_entry *conflict_entry[3]; + git_strarray after; + + char *paths[] = { "conflicts-one.txt" }; + char *after_shas[] = { "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81" }; + + test_reset_default__cleanup(); + initialize("mergedrepo"); + + _pathspecs.strings = paths; + _pathspecs.count = 1; + after.strings = after_shas; + after.count = 1; + + cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1], + &conflict_entry[2], _index, "conflicts-one.txt")); + + cl_git_pass(git_revparse_single(&_target, _repo, "9a05ccb")); + cl_git_pass(git_reset_default(_repo, _target, &_pathspecs)); + + assert_content_in_index(&_pathspecs, true, &after); + + cl_assert_equal_i(GIT_ENOTFOUND, git_index_conflict_get(&conflict_entry[0], + &conflict_entry[1], &conflict_entry[2], _index, "conflicts-one.txt")); +} + +/* +$ git reset HEAD -- "I_am_not_there.txt" "me_neither.txt" +Unstaged changes after reset: +... +*/ +void test_reset_default__resetting_unknown_filepaths_does_not_fail(void) +{ + char *paths[] = { "I_am_not_there.txt", "me_neither.txt" }; + + _pathspecs.strings = paths; + _pathspecs.count = 2; + + assert_content_in_index(&_pathspecs, false, NULL); + + cl_git_pass(git_revparse_single(&_target, _repo, "HEAD")); + cl_git_pass(git_reset_default(_repo, _target, &_pathspecs)); + + assert_content_in_index(&_pathspecs, false, NULL); +} |
