提交 90a2bf9c 编写于 作者: J Junio C Hamano

Merge branch 'sd/init-template'

* sd/init-template:
  wrap-for-bin: do not export an empty GIT_TEMPLATE_DIR
  t/t0001-init.sh: add test for 'init with init.templatedir set'
  init: having keywords without value is not a global error.
  Add a "TEMPLATE DIRECTORY" section to git-init[1].
  Add `init.templatedir` configuration variable.
......@@ -1210,6 +1210,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].
......
......@@ -149,8 +149,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
......
......@@ -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 sample "hook" files.
The suggested patterns and hook files are all modifiable and extensible.
EXAMPLES
--------
......
......@@ -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,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.
......
......@@ -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`" &&
......
......@@ -7,9 +7,15 @@
# @@BUILD_DIR@@ and @@PROG@@.
GIT_EXEC_PATH='@@BUILD_DIR@@'
GIT_TEMPLATE_DIR='@@BUILD_DIR@@/templates/blt'
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@@" "$@"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册