]> asedeno.scripts.mit.edu Git - git.git/commitdiff
init: handle empty "template" parameter
authorJeff King <peff@peff.net>
Mon, 28 Jul 2008 06:02:04 +0000 (02:02 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 28 Jul 2008 06:14:03 +0000 (23:14 -0700)
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>
builtin-init-db.c
t/t0001-init.sh

index 38b4fcb6db547cf6b7a814db621e6f05b583c420..baf0d09ac4ea372b4015d399560a133b401b55cc 100644 (file)
@@ -117,6 +117,8 @@ static void copy_templates(const char *template_dir)
                template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
        if (!template_dir)
                template_dir = system_path(DEFAULT_GIT_TEMPLATE_DIR);
+       if (!template_dir[0])
+               return;
        strcpy(template_path, template_dir);
        template_len = strlen(template_path);
        if (template_path[template_len-1] != '/') {
index 2a38d98cb46ec5392093dc3c0eedf28d6f56c96b..620da5b32041b1ad69bfdcb6d139f2705386a5ff 100755 (executable)
@@ -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