Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2008-07-28 10:02:04 +0400
committerJunio C Hamano <gitster@pobox.com>2008-08-02 09:41:07 +0400
commitd65d2b2fb44a8bc0fc917aaca973ab7ad14d13b4 (patch)
treeba28d620693bbf0e0c545bbcd070d445b9df6ef8
parent1e5f7add985dbccc0e811dbb6eff5047d8843118 (diff)
init: handle empty "template" parameter
If a user passes "--template=", then our template parameter is blank. Unfortunately, copy_templates() assumes it has at least one character, and does all sorts of bad things like reading from template[-1] and then proceeding to link all of '/' into the .git directory. This patch just checks for that condition in copy_templates and aborts. As a side effect, this means that --template= now has the meaning "don't copy any templates." Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin-init-db.c2
-rwxr-xr-xt/t0001-init.sh26
2 files changed, 28 insertions, 0 deletions
diff --git a/builtin-init-db.c b/builtin-init-db.c
index e23b8438c7..c68a3b1e74 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -127,6 +127,8 @@ static void copy_templates(const char *template_dir)
template_dir = strbuf_detach(&d, NULL);
}
}
+ if (!template_dir[0])
+ return;
strcpy(template_path, template_dir);
template_len = strlen(template_path);
if (template_path[template_len-1] != '/') {
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index d31887f9bf..c0b781ae49 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -141,4 +141,30 @@ test_expect_success 'reinit' '
test_cmp again/empty again/err2
'
+test_expect_success 'init with --template' '
+ mkdir template-source &&
+ echo content >template-source/file &&
+ (
+ mkdir template-custom &&
+ cd template-custom &&
+ git init --template=../template-source
+ ) &&
+ test_cmp template-source/file template-custom/.git/file
+'
+
+test_expect_success 'init with --template (blank)' '
+ (
+ mkdir template-plain &&
+ cd template-plain &&
+ git init
+ ) &&
+ test -f template-plain/.git/info/exclude &&
+ (
+ mkdir template-blank &&
+ cd template-blank &&
+ git init --template=
+ ) &&
+ ! test -f template-blank/.git/info/exclude
+'
+
test_done