Add init.templatedir
configuration variable.
Rather than having to pass --template to git init and clone for a custom setup, `init.templatedir` may be set in '~/.gitconfig'. The environment variable GIT_TEMPLATE_DIR can already be used for this but this is nicer. System administrators may prefer using this variable in the system-wide config file to point at a locally modified copy (e.g. /etc/gittemplate) rather than editing vanilla template files in '/usr/share'. Signed-off-by: Steven Drake <sdrake@xnet.co.nz> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
e923eaeb90
commit
90b45187ba
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
static int init_is_bare_repository = 0;
|
static int init_is_bare_repository = 0;
|
||||||
static int init_shared_repository = -1;
|
static int init_shared_repository = -1;
|
||||||
|
static const char *init_db_template_dir;
|
||||||
|
|
||||||
static void safe_create_dir(const char *dir, int share)
|
static void safe_create_dir(const char *dir, int share)
|
||||||
{
|
{
|
||||||
@ -120,6 +121,8 @@ static void copy_templates(const char *template_dir)
|
|||||||
|
|
||||||
if (!template_dir)
|
if (!template_dir)
|
||||||
template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
|
template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
|
||||||
|
if (!template_dir)
|
||||||
|
template_dir = init_db_template_dir;
|
||||||
if (!template_dir)
|
if (!template_dir)
|
||||||
template_dir = system_path(DEFAULT_GIT_TEMPLATE_DIR);
|
template_dir = system_path(DEFAULT_GIT_TEMPLATE_DIR);
|
||||||
if (!template_dir[0])
|
if (!template_dir[0])
|
||||||
@ -165,6 +168,16 @@ static void copy_templates(const char *template_dir)
|
|||||||
closedir(dir);
|
closedir(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int git_init_db_config(const char *k, const char *v, void *cb)
|
||||||
|
{
|
||||||
|
if (!v)
|
||||||
|
return config_error_nonbool(k);
|
||||||
|
if (!strcmp(k, "init.templatedir"))
|
||||||
|
return git_config_pathname(&init_db_template_dir, k, v);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int create_default_files(const char *template_path)
|
static int create_default_files(const char *template_path)
|
||||||
{
|
{
|
||||||
const char *git_dir = get_git_dir();
|
const char *git_dir = get_git_dir();
|
||||||
@ -190,6 +203,9 @@ static int create_default_files(const char *template_path)
|
|||||||
safe_create_dir(git_path("refs/heads"), 1);
|
safe_create_dir(git_path("refs/heads"), 1);
|
||||||
safe_create_dir(git_path("refs/tags"), 1);
|
safe_create_dir(git_path("refs/tags"), 1);
|
||||||
|
|
||||||
|
/* Just look for `init.templatedir` */
|
||||||
|
git_config(git_init_db_config, NULL);
|
||||||
|
|
||||||
/* First copy the templates -- we might have the default
|
/* First copy the templates -- we might have the default
|
||||||
* config file there, in which case we would want to read
|
* config file there, in which case we would want to read
|
||||||
* from it after installing.
|
* from it after installing.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user