Commit fb11544b589cea1d1d490c451704e6328a882033

Carlos Martín Nieto 2017-10-09T11:59:19

Merge pull request #4371 from pks-t/pks/test-checkout-tree-refactoring tests: checkout::tree: verify status entrycount changes on chmod

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);