Commit a025907e by Linquize

Can load default template directory

parent b99b10f2
......@@ -763,7 +763,8 @@ static int git_futils_find_in_dirlist(
continue;
GITERR_CHECK_ERROR(git_buf_set(path, scan, len));
GITERR_CHECK_ERROR(git_buf_joinpath(path, path->ptr, name));
if (name)
GITERR_CHECK_ERROR(git_buf_joinpath(path, path->ptr, name));
if (git_path_exists(path->ptr))
return 0;
......@@ -792,6 +793,12 @@ int git_futils_find_xdg_file(git_buf *path, const char *filename)
path, filename, GIT_FUTILS_DIR_XDG, "global/xdg");
}
int git_futils_find_template_dir(git_buf *path)
{
return git_futils_find_in_dirlist(
path, NULL, GIT_FUTILS_DIR_TEMPLATE, "template");
}
int git_futils_fake_symlink(const char *old, const char *new)
{
int retcode = GIT_ERROR;
......
......@@ -306,6 +306,14 @@ extern int git_futils_find_xdg_file(git_buf *path, const char *filename);
*/
extern int git_futils_find_system_file(git_buf *path, const char *filename);
/**
* Find template directory.
*
* @param path buffer to write the full path into
* @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error
*/
extern int git_futils_find_template_dir(git_buf *path);
typedef enum {
GIT_FUTILS_DIR_SYSTEM = 0,
GIT_FUTILS_DIR_GLOBAL = 1,
......
......@@ -33,8 +33,6 @@
#define GIT_REPO_VERSION 0
#define GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
static void set_odb(git_repository *repo, git_odb *odb)
{
if (odb) {
......@@ -1136,6 +1134,9 @@ static int repo_init_structure(
if (external_tpl) {
git_config *cfg;
const char *tdir;
git_buf template_buf = GIT_BUF_INIT;
git_futils_find_template_dir(&template_buf);
if (opts->template_path)
tdir = opts->template_path;
......@@ -1150,7 +1151,7 @@ static int repo_init_structure(
return error;
giterr_clear();
tdir = GIT_TEMPLATE_DIR;
tdir = template_buf.ptr;
}
error = git_futils_cp_r(tdir, repo_dir,
......@@ -1158,14 +1159,17 @@ static int repo_init_structure(
GIT_CPDIR_SIMPLE_TO_MODE, dmode);
if (error < 0) {
if (strcmp(tdir, GIT_TEMPLATE_DIR) != 0)
if (strcmp(tdir, template_buf.ptr) != 0) {
git_buf_free(&template_buf);
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment