Skip to content

Commit 90b4518

Browse files
Steven Drakegitster
Steven Drake
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e923eae commit 90b4518

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

builtin-init-db.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
static int init_is_bare_repository = 0;
2222
static int init_shared_repository = -1;
23+
static const char *init_db_template_dir;
2324

2425
static void safe_create_dir(const char *dir, int share)
2526
{
@@ -120,6 +121,8 @@ static void copy_templates(const char *template_dir)
120121

121122
if (!template_dir)
122123
template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
124+
if (!template_dir)
125+
template_dir = init_db_template_dir;
123126
if (!template_dir)
124127
template_dir = system_path(DEFAULT_GIT_TEMPLATE_DIR);
125128
if (!template_dir[0])
@@ -165,6 +168,16 @@ static void copy_templates(const char *template_dir)
165168
closedir(dir);
166169
}
167170

171+
static int git_init_db_config(const char *k, const char *v, void *cb)
172+
{
173+
if (!v)
174+
return config_error_nonbool(k);
175+
if (!strcmp(k, "init.templatedir"))
176+
return git_config_pathname(&init_db_template_dir, k, v);
177+
178+
return 0;
179+
}
180+
168181
static int create_default_files(const char *template_path)
169182
{
170183
const char *git_dir = get_git_dir();
@@ -190,6 +203,9 @@ static int create_default_files(const char *template_path)
190203
safe_create_dir(git_path("refs/heads"), 1);
191204
safe_create_dir(git_path("refs/tags"), 1);
192205

206+
/* Just look for `init.templatedir` */
207+
git_config(git_init_db_config, NULL);
208+
193209
/* First copy the templates -- we might have the default
194210
* config file there, in which case we would want to read
195211
* from it after installing.

0 commit comments

Comments
 (0)