8000 Merge pull request #6106 from ammgws/fixtemplateerr · Murmele/libgit2@f9c4dc1 · GitHub
[go: up one dir, main page]

Skip to content

Commit f9c4dc1

Browse files
authored
Merge pull request libgit2#6106 from ammgws/fixtemplateerr
Fix repo init when template dir is non-existent
2 parents 1974383 + 3461aaf commit f9c4dc1

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/repository.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2032,8 +2032,13 @@ static int repo_init_structure(
20322032
git_str_dispose(&template_buf);
20332033
git_config_free(cfg);
20342034

2035+
/* If tdir does not exist, then do not error out. This matches the
2036+
* behaviour of git(1), which just prints a warning and continues.
2037+
* TODO: issue warning when warning API is available.
2038+
* `git` prints to stderr: 'warning: templates not found in /path/to/tdir'
2039+
*/
20352040
if (error < 0) {
2036-
if (!default_template)
2041+
if (!default_template && error != GIT_ENOTFOUND)
20372042
return error;
20382043

20392044
/* if template was default, ignore error and use internal */

tests/repo/template.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,13 @@ void test_repo_template__empty_template_path(void)
293293

294294
setup_repo("foo", &opts);
295295 6D35
}
296+
297+
void test_repo_template__nonexistent_template_path(void)
298+
{
299+
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
300+
301+
opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE;
302+
opts.template_path = "/tmp/path/that/does/not/exist/for/libgit2/test";
303+
304+
setup_repo("bar", &opts);
305+
}

0 commit comments

Comments
 (0)
0