From 90b45187ba51a15c8a80680597240e32421f53bb Mon Sep 17 00:00:00 2001 From: Steven Drake Date: Wed, 17 Feb 2010 12:42:31 +1300 Subject: [PATCH 1/5] 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 Signed-off-by: Junio C Hamano --- builtin-init-db.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/builtin-init-db.c b/builtin-init-db.c index dd84caecb..0eb9efc93 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) { @@ -120,6 +121,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]) @@ -165,6 +168,16 @@ 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 (!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) { 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/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. From d8a8488d569420c4e0a96a8df36b246d888e68d4 Mon Sep 17 00:00:00 2001 From: Steven Drake Date: Wed, 17 Feb 2010 12:44:46 +1300 Subject: [PATCH 2/5] Add a "TEMPLATE DIRECTORY" section to git-init[1]. Create a more inoformative section to describe template directory and refer to it in config.txt and with the '--template' option of git-init and git-clone commands. Signed-off-by: Steven Drake Signed-off-by: Junio C Hamano --- Documentation/config.txt | 4 ++++ Documentation/git-clone.txt | 3 +-- Documentation/git-init.txt | 29 +++++++++++++++++++++-------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 4c36aa95b..310d36b20 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -1200,6 +1200,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 f43c8b2c0..3919b7d44 100644 --- a/Documentation/git-clone.txt +++ b/Documentation/git-clone.txt @@ -149,8 +149,7 @@ objects from the source repository into a pack in the cloned repository. --template=:: 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 :: Create a 'shallow' clone with a history truncated to the diff --git a/Documentation/git-init.txt b/Documentation/git-init.txt index 7ee102da4..246b07ebf 100644 --- a/Documentation/git-init.txt +++ b/Documentation/git-init.txt @@ -28,14 +28,8 @@ current working directory. --template=:: -Provide the directory from which templates will be used. The default template -directory is `/usr/share/git-core/templates`. - -When specified, `` 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 sample "hook" files. +The suggested patterns and hook files are all modifiable and extensible. EXAMPLES -------- From b02a17f2b7d0d3f5899ffdd9709ded8cea8ae019 Mon Sep 17 00:00:00 2001 From: Steven Drake Date: Fri, 26 Feb 2010 17:00:20 +1300 Subject: [PATCH 3/5] init: having keywords without value is not a global error. We may later add a new configuration variable in "init" section that takes a boolean value. Erroring out at the beginning of the config parser makes life harder for later enhancement. The existing configuration variable is parsed by git_config_pathname() that checks and rejects init.templatedir that is unset without this extra check. Remove it. Signed-off-by: Steven Drake Signed-off-by: Junio C Hamano --- builtin-init-db.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/builtin-init-db.c b/builtin-init-db.c index 0eb9efc93..a54f48978 100644 --- a/builtin-init-db.c +++ b/builtin-init-db.c @@ -170,8 +170,6 @@ static void copy_templates(const char *template_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); From a94d305bf8043a7a0579037c7e52e632613410f7 Mon Sep 17 00:00:00 2001 From: Steven Drake Date: Fri, 26 Feb 2010 17:00:21 +1300 Subject: [PATCH 4/5] t/t0001-init.sh: add test for 'init with init.templatedir set' Requires a small change to wrap-for-bin.sh in order to work. Signed-off-by: Steven Drake Signed-off-by: Junio C Hamano --- t/t0001-init.sh | 19 +++++++++++++++++++ wrap-for-bin.sh | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 538650479..675773479 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -167,6 +167,25 @@ test_expect_success 'init with --template (blank)' ' ! test -f template-blank/.git/info/exclude ' +test_expect_success 'init with init.templatedir set' ' + mkdir templatedir-source && + echo Content >templatedir-source/file && + ( + HOME="`pwd`" && + export HOME && + test_config="${HOME}/.gitconfig" && + git config -f "$test_config" init.templatedir "${HOME}/templatedir-source" && + mkdir templatedir-set && + cd templatedir-set && + unset GIT_CONFIG_NOGLOBAL && + unset GIT_TEMPLATE_DIR && + NO_SET_GIT_TEMPLATE_DIR=t && + export NO_SET_GIT_TEMPLATE_DIR && + git init + ) && + test_cmp templatedir-source/file templatedir-set/.git/file +' + test_expect_success 'init --bare/--shared overrides system/global config' ' ( HOME="`pwd`" && diff --git a/wrap-for-bin.sh b/wrap-for-bin.sh index c5075c9c6..aece782a8 100644 --- a/wrap-for-bin.sh +++ b/wrap-for-bin.sh @@ -7,7 +7,8 @@ # @@BUILD_DIR@@ and @@PROG@@. GIT_EXEC_PATH='@@BUILD_DIR@@' -GIT_TEMPLATE_DIR='@@BUILD_DIR@@/templates/blt' +test -z "$NO_SET_GIT_TEMPLATE_DIR" && + GIT_TEMPLATE_DIR='@@BUILD_DIR@@/templates/blt' GITPERLLIB='@@BUILD_DIR@@/perl/blib/lib' PATH='@@BUILD_DIR@@/bin-wrappers:'"$PATH" export GIT_EXEC_PATH GIT_TEMPLATE_DIR GITPERLLIB PATH From 160ad147fe9f644fc35224095e1d1a01be0208de Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 2 Mar 2010 16:27:03 -0800 Subject: [PATCH 5/5] wrap-for-bin: do not export an empty GIT_TEMPLATE_DIR With bash on some platforms (e.g. FreeBSD 8.0), exporting an unset variable does not "unexport" it. The called process gets an empty string from getenv(3) instead of NULL. Signed-off-by: Junio C Hamano --- wrap-for-bin.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/wrap-for-bin.sh b/wrap-for-bin.sh index aece782a8..09feb1f73 100644 --- a/wrap-for-bin.sh +++ b/wrap-for-bin.sh @@ -7,10 +7,15 @@ # @@BUILD_DIR@@ and @@PROG@@. GIT_EXEC_PATH='@@BUILD_DIR@@' -test -z "$NO_SET_GIT_TEMPLATE_DIR" && +if test -n "$NO_SET_GIT_TEMPLATE_DIR" +then + unset GIT_TEMPLATE_DIR +else GIT_TEMPLATE_DIR='@@BUILD_DIR@@/templates/blt' + export GIT_TEMPLATE_DIR +fi GITPERLLIB='@@BUILD_DIR@@/perl/blib/lib' PATH='@@BUILD_DIR@@/bin-wrappers:'"$PATH" -export GIT_EXEC_PATH GIT_TEMPLATE_DIR GITPERLLIB PATH +export GIT_EXEC_PATH GITPERLLIB PATH exec "${GIT_EXEC_PATH}/@@PROG@@" "$@"