diff options
author | Vicent Martà <vicent@github.com> | 2013-09-20 09:22:19 -0700 |
---|---|---|
committer | Vicent Martà <vicent@github.com> | 2013-09-20 09:22:19 -0700 |
commit | 2c9ed02eae0a3df9650fb5834303a72dda098e55 (patch) | |
tree | 1b294d7dfd3b44a14b5784545346264099a66118 | |
parent | 5a284edca42dd75cf62b3fe75020819fcfcea9f3 (diff) | |
parent | 417472e317a8680123f2fa4f46e1e3c21315326d (diff) | |
download | libgit2-2c9ed02eae0a3df9650fb5834303a72dda098e55.tar.gz |
Merge pull request #1859 from linquize/init.templatedir
Make init.templatedir work
-rw-r--r-- | src/repository.c | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/src/repository.c b/src/repository.c index d1b7d9131..6dea48790 100644 --- a/src/repository.c +++ b/src/repository.c @@ -1132,44 +1132,39 @@ static int repo_init_structure( /* Copy external template if requested */ if (external_tpl) { - git_config *cfg; - const char *tdir; + git_config *cfg = NULL; + const char *tdir = NULL; + bool default_template = false; git_buf template_buf = GIT_BUF_INIT; - git_futils_find_template_dir(&template_buf); - if (opts->template_path) tdir = opts->template_path; - else if ((error = git_config_open_default(&cfg)) < 0) - return error; - else { + else if ((error = git_config_open_default(&cfg)) >= 0) { error = git_config_get_string(&tdir, cfg, "init.templatedir"); - - git_config_free(cfg); - - if (error && error != GIT_ENOTFOUND) - return error; - giterr_clear(); - tdir = template_buf.ptr; + } + + if (!tdir) { + if ((error = git_futils_find_template_dir(&template_buf)) >= 0); + tdir = template_buf.ptr; + default_template = true; } error = git_futils_cp_r(tdir, repo_dir, GIT_CPDIR_COPY_SYMLINKS | GIT_CPDIR_CHMOD_DIRS | GIT_CPDIR_SIMPLE_TO_MODE, dmode); + git_buf_free(&template_buf); + git_config_free(cfg); if (error < 0) { - if (strcmp(tdir, template_buf.ptr) != 0) { - git_buf_free(&template_buf); + if (!default_template) return error; - } /* if template was default, ignore error and use internal */ giterr_clear(); external_tpl = false; error = 0; } - git_buf_free(&template_buf); } /* Copy internal template |