Merge pull request #4371 from pks-t/pks/test-checkout-tree-refactoring tests: checkout::tree: verify status entrycount changes on chmod
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
diff --git a/tests/checkout/tree.c b/tests/checkout/tree.c
index c3475f4..56513ea 100644
--- a/tests/checkout/tree.c
+++ b/tests/checkout/tree.c
@@ -10,6 +10,16 @@ static git_repository *g_repo;
static git_checkout_options g_opts;
static git_object *g_object;
+static void assert_status_entrycount(git_repository *repo, size_t count)
+{
+ git_status_list *status;
+
+ cl_git_pass(git_status_list_new(&status, repo, NULL));
+ cl_assert_equal_i(count, git_status_list_entrycount(status));
+
+ git_status_list_free(status);
+}
+
void test_checkout_tree__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo");
@@ -1480,7 +1490,6 @@ void test_checkout_tree__baseline_is_empty_when_no_index(void)
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
git_reference *head;
git_object *obj;
- git_status_list *status;
size_t conflicts = 0;
assert_on_branch(g_repo, "master");
@@ -1506,9 +1515,7 @@ void test_checkout_tree__baseline_is_empty_when_no_index(void)
opts.checkout_strategy |= GIT_CHECKOUT_FORCE;
cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
- cl_git_pass(git_status_list_new(&status, g_repo, NULL));
- cl_assert_equal_i(0, git_status_list_entrycount(status));
- git_status_list_free(status);
+ assert_status_entrycount(g_repo, 0);
git_object_free(obj);
git_reference_free(head);
@@ -1519,7 +1526,6 @@ void test_checkout_tree__mode_change_is_force_updated(void)
git_index *index;
git_reference *head;
git_object *obj;
- git_status_list *status;
if (!cl_is_chmod_supported())
clar__skip();
@@ -1530,29 +1536,22 @@ void test_checkout_tree__mode_change_is_force_updated(void)
cl_git_pass(git_reference_peel(&obj, head, GIT_OBJ_COMMIT));
cl_git_pass(git_reset(g_repo, obj, GIT_RESET_HARD, NULL));
-
- cl_git_pass(git_status_list_new(&status, g_repo, NULL));
- cl_assert_equal_i(0, git_status_list_entrycount(status));
- git_status_list_free(status);
+ assert_status_entrycount(g_repo, 0);
/* update the mode on-disk */
cl_must_pass(p_chmod("testrepo/README", 0755));
+ assert_status_entrycount(g_repo, 1);
cl_git_pass(git_checkout_tree(g_repo, obj, &g_opts));
-
- cl_git_pass(git_status_list_new(&status, g_repo, NULL));
- cl_assert_equal_i(0, git_status_list_entrycount(status));
- git_status_list_free(status);
+ assert_status_entrycount(g_repo, 0);
/* update the mode on-disk and in the index */
cl_must_pass(p_chmod("testrepo/README", 0755));
cl_must_pass(git_index_add_bypath(index, "README"));
+ assert_status_entrycount(g_repo, 1);
cl_git_pass(git_checkout_tree(g_repo, obj, &g_opts));
-
- cl_git_pass(git_status_list_new(&status, g_repo, NULL));
- cl_assert_equal_i(0, git_status_list_entrycount(status));
- git_status_list_free(status);
+ assert_status_entrycount(g_repo, 0);
git_object_free(obj);
git_reference_free(head);