diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2021-11-22 11:23:50 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-22 11:23:50 -0500 |
commit | f9c4dc10d90732cfbe2271dd58b01dd8f4003d15 (patch) | |
tree | 8b75f189916e1061d7ae5943e3e56c97a1e91bac | |
parent | 19743830e651bc67701cf99caf540093b62a35fa (diff) | |
parent | 3461aaf77aad4240ec921697293dc681a8564023 (diff) | |
download | libgit2-f9c4dc10d90732cfbe2271dd58b01dd8f4003d15.tar.gz |
Merge pull request #6106 from ammgws/fixtemplateerr
Fix repo init when template dir is non-existent
-rw-r--r-- | src/repository.c | 7 | ||||
-rw-r--r-- | tests/repo/template.c | 10 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/repository.c b/src/repository.c index 3b3f7ca82..8059f1081 100644 --- a/src/repository.c +++ b/src/repository.c @@ -2032,8 +2032,13 @@ static int repo_init_structure( git_str_dispose(&template_buf); git_config_free(cfg); + /* If tdir does not exist, then do not error out. This matches the + * behaviour of git(1), which just prints a warning and continues. + * TODO: issue warning when warning API is available. + * `git` prints to stderr: 'warning: templates not found in /path/to/tdir' + */ if (error < 0) { - if (!default_template) + if (!default_template && error != GIT_ENOTFOUND) return error; /* if template was default, ignore error and use internal */ diff --git a/tests/repo/template.c b/tests/repo/template.c index b0af96e36..e8fe266cf 100644 --- a/tests/repo/template.c +++ b/tests/repo/template.c @@ -293,3 +293,13 @@ void test_repo_template__empty_template_path(void) setup_repo("foo", &opts); } + +void test_repo_template__nonexistent_template_path(void) +{ + git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; + + opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE; + opts.template_path = "/tmp/path/that/does/not/exist/for/libgit2/test"; + + setup_repo("bar", &opts); +} |