Skip to content

Commit 880dfc5

Browse files
committed
tests: checkout::tree: extract check for status entrycount
There are multiple locations where we have the same code to check whether the count of status list entries of a repository matches an expected number. Extract that into a common function.
1 parent 38e769c commit 880dfc5

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

tests/checkout/tree.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ static git_repository *g_repo;
1010
static git_checkout_options g_opts;
1111
static git_object *g_object;
1212

13+
static void assert_status_entrycount(git_repository *repo, size_t count)
14+
{
15+
git_status_list *status;
16+
17+
cl_git_pass(git_status_list_new(&status, repo, NULL));
18+
cl_assert_equal_i(count, git_status_list_entrycount(status));
19+
20+
git_status_list_free(status);
21+
}
22+
1323
void test_checkout_tree__initialize(void)
1424
{
1525
g_repo = cl_git_sandbox_init("testrepo");
@@ -1480,7 +1490,6 @@ void test_checkout_tree__baseline_is_empty_when_no_index(void)
14801490
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
14811491
git_reference *head;
14821492
git_object *obj;
1483-
git_status_list *status;
14841493
size_t conflicts = 0;
14851494

14861495
assert_on_branch(g_repo, "master");
@@ -1506,9 +1515,7 @@ void test_checkout_tree__baseline_is_empty_when_no_index(void)
15061515
opts.checkout_strategy |= GIT_CHECKOUT_FORCE;
15071516
cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
15081517

1509-
cl_git_pass(git_status_list_new(&status, g_repo, NULL));
1510-
cl_assert_equal_i(0, git_status_list_entrycount(status));
1511-
git_status_list_free(status);
1518+
assert_status_entrycount(g_repo, 0);
15121519

15131520
git_object_free(obj);
15141521
git_reference_free(head);
@@ -1519,7 +1526,6 @@ void test_checkout_tree__mode_change_is_force_updated(void)
15191526
git_index *index;
15201527
git_reference *head;
15211528
git_object *obj;
1522-
git_status_list *status;
15231529

15241530
if (!cl_is_chmod_supported())
15251531
clar__skip();
@@ -1530,29 +1536,20 @@ void test_checkout_tree__mode_change_is_force_updated(void)
15301536
cl_git_pass(git_reference_peel(&obj, head, GIT_OBJ_COMMIT));
15311537

15321538
cl_git_pass(git_reset(g_repo, obj, GIT_RESET_HARD, NULL));
1533-
1534-
cl_git_pass(git_status_list_new(&status, g_repo, NULL));
1535-
cl_assert_equal_i(0, git_status_list_entrycount(status));
1536-
git_status_list_free(status);
1539+
assert_status_entrycount(g_repo, 0);
15371540

15381541
/* update the mode on-disk */
15391542
cl_must_pass(p_chmod("testrepo/README", 0755));
15401543

15411544
cl_git_pass(git_checkout_tree(g_repo, obj, &g_opts));
1542-
1543-
cl_git_pass(git_status_list_new(&status, g_repo, NULL));
1544-
cl_assert_equal_i(0, git_status_list_entrycount(status));
1545-
git_status_list_free(status);
1545+
assert_status_entrycount(g_repo, 0);
15461546

15471547
/* update the mode on-disk and in the index */
15481548
cl_must_pass(p_chmod("testrepo/README", 0755));
15491549
cl_must_pass(git_index_add_bypath(index, "README"));
15501550

15511551
cl_git_pass(git_checkout_tree(g_repo, obj, &g_opts));
1552-
1553-
cl_git_pass(git_status_list_new(&status, g_repo, NULL));
1554-
cl_assert_equal_i(0, git_status_list_entrycount(status));
1555-
git_status_list_free(status);
1552+
assert_status_entrycount(g_repo, 0);
15561553

15571554
git_object_free(obj);
15581555
git_reference_free(head);

0 commit comments

Comments
 (0)