mirror of
https://git.proxmox.com/git/libgit2
synced 2026-01-25 20:27:16 +00:00
iterator: workdir tests with submodules
Ensure that when specifying start/end paths, or pathlists, that we deal correctly with submodules.
This commit is contained in:
parent
c3d195f1d9
commit
908d8de8c3
@ -2,6 +2,7 @@
|
||||
#include "iterator.h"
|
||||
#include "repository.h"
|
||||
#include "fileops.h"
|
||||
#include "../submodule/submodule_helpers.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
static git_repository *g_repo;
|
||||
@ -1640,6 +1641,85 @@ void test_repo_iterator__workdir_pathlist_with_dirs(void)
|
||||
git_vector_free(&filelist);
|
||||
}
|
||||
|
||||
void test_repo_iterator__workdir_bounded_submodules(void)
|
||||
{
|
||||
git_iterator *i;
|
||||
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
|
||||
git_vector filelist;
|
||||
git_index *index;
|
||||
git_tree *head;
|
||||
|
||||
cl_git_pass(git_vector_init(&filelist, 5, NULL));
|
||||
|
||||
g_repo = setup_fixture_submod2();
|
||||
cl_git_pass(git_repository_index(&index, g_repo));
|
||||
cl_git_pass(git_repository_head_tree(&head, g_repo));
|
||||
|
||||
/* Test that a submodule matches */
|
||||
{
|
||||
const char *expected[] = { "sm_changed_head" };
|
||||
size_t expected_len = 1;
|
||||
|
||||
git_vector_clear(&filelist);
|
||||
cl_git_pass(git_vector_insert(&filelist, "sm_changed_head"));
|
||||
|
||||
i_opts.pathlist.strings = (char **)filelist.contents;
|
||||
i_opts.pathlist.count = filelist.length;
|
||||
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
|
||||
|
||||
cl_git_pass(git_iterator_for_workdir(&i, g_repo, index, head, &i_opts));
|
||||
expect_iterator_items(i, expected_len, expected, expected_len, expected);
|
||||
git_iterator_free(i);
|
||||
}
|
||||
|
||||
/* Test that a submodule never matches when suffixed with a '/' */
|
||||
{
|
||||
git_vector_clear(&filelist);
|
||||
cl_git_pass(git_vector_insert(&filelist, "sm_changed_head/"));
|
||||
|
||||
i_opts.pathlist.strings = (char **)filelist.contents;
|
||||
i_opts.pathlist.count = filelist.length;
|
||||
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
|
||||
|
||||
cl_git_pass(git_iterator_for_workdir(&i, g_repo, index, head, &i_opts));
|
||||
cl_git_fail_with(GIT_ITEROVER, git_iterator_advance(NULL, i));
|
||||
git_iterator_free(i);
|
||||
}
|
||||
|
||||
/* Test that start/end work with a submodule */
|
||||
{
|
||||
const char *expected[] = { "sm_changed_head", "sm_changed_index" };
|
||||
size_t expected_len = 2;
|
||||
|
||||
i_opts.start = "sm_changed_head";
|
||||
i_opts.end = "sm_changed_index";
|
||||
i_opts.pathlist.strings = NULL;
|
||||
i_opts.pathlist.count = 0;
|
||||
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
|
||||
|
||||
cl_git_pass(git_iterator_for_workdir(&i, g_repo, index, head, &i_opts));
|
||||
expect_iterator_items(i, expected_len, expected, expected_len, expected);
|
||||
git_iterator_free(i);
|
||||
}
|
||||
|
||||
/* Test that start and end do not allow '/' suffixes of submodules */
|
||||
{
|
||||
i_opts.start = "sm_changed_head/";
|
||||
i_opts.end = "sm_changed_head/";
|
||||
i_opts.pathlist.strings = NULL;
|
||||
i_opts.pathlist.count = 0;
|
||||
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
|
||||
|
||||
cl_git_pass(git_iterator_for_workdir(&i, g_repo, index, head, &i_opts));
|
||||
cl_git_fail_with(GIT_ITEROVER, git_iterator_advance(NULL, i));
|
||||
git_iterator_free(i);
|
||||
}
|
||||
|
||||
git_vector_free(&filelist);
|
||||
git_index_free(index);
|
||||
git_tree_free(head);
|
||||
}
|
||||
|
||||
void test_repo_iterator__treefilelist(void)
|
||||
{
|
||||
git_iterator *i;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user