Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0028218

Browse files
committed
repo::init tests: test a template dir with leading dot
Ensure that we can handle template directories that begin with a leading dot.
1 parent 5c042c5 commit 0028218

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

tests/repo/init.c

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ enum repo_mode {
1212

1313
static git_repository *_repo = NULL;
1414
static git_buf _global_path = GIT_BUF_INIT;
15+
static git_buf _tmp_path = GIT_BUF_INIT;
1516
static mode_t g_umask = 0;
1617

1718
void test_repo_init__initialize(void)
@@ -33,6 +34,10 @@ void test_repo_init__cleanup(void)
3334
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL,
3435
_global_path.ptr);
3536
git_buf_free(&_global_path);
37+
38+
if (_tmp_path.size > 0 && git_path_isdir(_tmp_path.ptr))
39+
git_futils_rmdir_r(_tmp_path.ptr, NULL, GIT_RMDIR_REMOVE_FILES);
40+
git_buf_free(&_tmp_path);
3641
}
3742

3843
static void cleanup_repository(void *path)
@@ -544,14 +549,14 @@ static void configure_templatedir(const char *template_path)
544549
git_buf config_data = GIT_BUF_INIT;
545550

546551
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH,
547-
GIT_CONFIG_LEVEL_GLOBAL, &config_path));
548-
cl_git_pass(git_buf_puts(&config_path, ".tmp"));
552+
GIT_CONFIG_LEVEL_GLOBAL, &_tmp_path));
553+
cl_git_pass(git_buf_puts(&_tmp_path, ".tmp"));
549554
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH,
550-
GIT_CONFIG_LEVEL_GLOBAL, config_path.ptr));
555+
GIT_CONFIG_LEVEL_GLOBAL, _tmp_path.ptr));
551556

552-
cl_must_pass(p_mkdir(config_path.ptr, 0777));
557+
cl_must_pass(p_mkdir(_tmp_path.ptr, 0777));
553558

554-
cl_git_pass(git_buf_joinpath(&config_path, config_path.ptr, ".gitconfig"));
559+
cl_git_pass(git_buf_joinpath(&config_path, _tmp_path.ptr, ".gitconfig"));
555560

556561
cl_git_pass(git_buf_printf(&config_data,
557562
"[init]\n\ttemplatedir = \"%s\"\n", template_path));
@@ -636,16 +641,39 @@ void test_repo_init__external_templates_specified_in_config(void)
636641

637642
cl_git_pass(git_repository_init_ext(&_repo, "templated.git", &opts));
638643

639-
cl_assert(git_repository_is_bare(_repo));
640-
641-
cl_assert(!git__suffixcmp(git_repository_path(_repo), "/templated.git/"));
642-
643644
validate_templates(_repo, "template");
644645
cl_fixture_cleanup("template");
645646

646647
git_buf_free(&template_path);
647648
}
648649

650+
void test_repo_init__external_templates_with_leading_dot(void)
651+
{
652+
git_buf template_path = GIT_BUF_INIT;
653+
654+
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
655+
656+
cl_set_cleanup(&cleanup_repository, "templated.git");
657+
template_sandbox("template");
658+
659+
cl_must_pass(p_rename("template", ".template_with_leading_dot"));
660+
661+
cl_git_pass(git_buf_joinpath(&template_path, clar_sandbox_path(),
662+
".template_with_leading_dot"));
663+
664+
configure_templatedir(template_path.ptr);
665+
666+
opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_BARE |
667+
GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE;
668+
669+
cl_git_pass(git_repository_init_ext(&_repo, "templated.git", &opts));
670+
671+
validate_templates(_repo, ".template_with_leading_dot");
672+
cl_fixture_cleanup(".template_with_leading_dot");
673+
674+
git_buf_free(&template_path);
675+
}
676+
649677
void test_repo_init__extended_with_template_and_shared_mode(void)
650678
{
651679
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;

0 commit comments

Comments
 (0)