threads / patch / 22684

patch, 2 partsAdd `init.templatedir` configuration variable.

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

## tl;dr

3 messages between Feb 16, 2010 and Feb 17, 2010. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Steven Drake· Feb 16, 2010, 23:42 UTC · lore

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(-)
Show changes to builtin-init-db.c +14 −0
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
Steven Drake· Feb 16, 2010, 23:44 UTC · re: Steven Drake · lore

[PATCH 2/2] Add a "TEMPLATE DIRECTORY" section to git-init[1].

The new section is supposed to be more informative, with references to it in config.txt and with the '--template' option of git-init and git-clone.

Signed-off-by: Steven Drake <sdrake@xnet.co.nz>
---
 Documentation/config.txt    |    4 ++++
 Documentation/git-clone.txt |    3 +--
 Documentation/git-init.txt  |   29 +++++++++++++++++++++--------
 3 files changed, 26 insertions(+), 10 deletions(-)
Show changes to 3 files +26 −10

Documentation/config.txt, Documentation/git-clone.txt, Documentation/git-init.txt

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 8acb613..da176e4 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1181,6 +1181,10 @@ imap::
 	The configuration variables in the 'imap' section are described
 	in linkgit:git-imap-send[1].
 
+init.templatedir::
+	Specify the directory from which templates will be copied.
+	(See the "TEMPLATE DIRECTORY" section of linkgit:git-init[1].)
+
 instaweb.browser::
 	Specify the program that will be used to browse your working
 	repository in gitweb. See linkgit:git-instaweb[1].
diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index 7ccd742..731b57e 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -143,8 +143,7 @@ objects from the source repository into a pack in the cloned repository.
 
 --template=<template_directory>::
 	Specify the directory from which templates will be used;
-	if unset the templates are taken from the installation
-	defined default, typically `/usr/share/git-core/templates`.
+	(See the "TEMPLATE DIRECTORY" section of linkgit:git-init[1].)
 
 --depth <depth>::
 	Create a 'shallow' clone with a history truncated to the
diff --git a/Documentation/git-init.txt b/Documentation/git-init.txt
index f081b24..dcab667 100644
--- a/Documentation/git-init.txt
+++ b/Documentation/git-init.txt
@@ -28,14 +28,8 @@ current working directory.
 
 --template=<template_directory>::
 
-Provide the directory from which templates will be used.  The default template
-directory is `/usr/share/git-core/templates`.
-
-When specified, `<template_directory>` is used as the source of the template
-files rather than the default.  The template files include some directory
-structure, some suggested "exclude patterns", and copies of non-executing
-"hook" files.  The suggested patterns and hook files are all modifiable and
-extensible.
+Specify the directory from which templates will be used.  (See the "TEMPLATE
+DIRECTORY" section below.)
 
 --shared[={false|true|umask|group|all|world|everybody|0xxx}]::
 
@@ -106,6 +100,25 @@ of the repository, such as installing the default hooks and
 setting the configuration variables.  The old name is retained
 for backward compatibility reasons.
 
+TEMPLATE DIRECTORY
+------------------
+
+The template directory contains files and directories that will be copied to
+the `$GIT_DIR` after it is created.
+
+The template directory used will (in order):
+
+ - The argument given with the `--template` option.
+
+ - The contents of the `$GIT_TEMPLATE_DIR` environment variable.
+
+ - The `init.templatedir` configuration variable.
+
+ - The default template directory: `/usr/share/git-core/templates`.
+
+The default template directory includes some directory structure, some
+suggested "exclude patterns", and copies of non-executing "hook" files.
+The suggested patterns and hook files are all modifiable and extensible.
 
 EXAMPLES
 --------
-- 
1.6.6.208.gcaa4e.dirty
Junio C Hamano· Feb 17, 2010, 18:59 UTC · re: Steven Drake · lore

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

Thanks; I will make a minor touch-ups to both of these patches and queue. You may want to add a few tests to t/t0001-init.sh before they get merged to 'next' branch and start cooking.

← back to recent threads