git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] Add `init.templatedir` configuration variable.

From
SDSteven Drake <sdrake@xnet.co.nz>
Date
Feb 16, 2010, 23:42 UTC
Message-ID
<alpine.LNX.2.00.1002171242150.2477@vqena.qenxr.bet.am>

Rather than having to pass --template to git init and clone for a custom setup, `init.templatedir` may be set in '~/.gitconfig' (Eg. git config --global --add init.templatedir ~/.gittemplate )

System administrators may prefer using this varialbe in the system-wide config file rather than editing files under '/usr/share'. (I.e. setting init.templatedir to $(prefix)/etc/gittempalte )

The environment variable GIT_TEMPLATE_DIR can already be used for this but the '.gitconfig' file is a much better place for this type of setting.

Signed-off-by: Steven Drake <sdrake@xnet.co.nz>
---
 builtin-init-db.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/builtin-init-db.c b/builtin-init-db.c
index dd84cae..a54f489 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -20,6 +20,7 @@
 
 static int init_is_bare_repository = 0;
 static int init_shared_repository = -1;
+static const char *init_db_template_dir;
 
 static void safe_create_dir(const char *dir, int share)
 {
@@ -121,6 +122,8 @@ static void copy_templates(const char *template_dir)
 	if (!template_dir)
 		template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
 	if (!template_dir)
+		template_dir = init_db_template_dir;
+	if (!template_dir)
 		template_dir = system_path(DEFAULT_GIT_TEMPLATE_DIR);
 	if (!template_dir[0])
 		return;
@@ -165,6 +168,14 @@ static void copy_templates(const char *template_dir)
 	closedir(dir);
 }
 
+static int git_init_db_config(const char *k, const char *v, void *cb)
+{
+	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)
 {
 	const char *git_dir = get_git_dir();
@@ -190,6 +201,9 @@ static int create_default_files(const char *template_path)
 	safe_create_dir(git_path("refs/heads"), 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
 	 * config file there, in which case we would want to read
 	 * from it after installing.
-- 
1.6.6.208.gcaa4e.dirty
Next: Steven Drake
Message 1 of 3 in “Add `init.templatedir` configuration variable.”
  1. 1/2 Add `init.templatedir` configuration variable.Steven Drake, Feb 16, 2010
  2. 2/2 Add a "TEMPLATE DIRECTORY" section to git-init[1].Steven Drake, Feb 16, 2010
  3. Junio C HamanoFeb 17, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.