summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1e5f7ad)
raw | patch | inline | side by side (parent: 1e5f7ad)
author | Jeff King <peff@peff.net> | |
Mon, 28 Jul 2008 06:02:04 +0000 (02:02 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sat, 2 Aug 2008 05:41:07 +0000 (22:41 -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>
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 | patch | blob | history | |
t/t0001-init.sh | patch | blob | history |
diff --git a/builtin-init-db.c b/builtin-init-db.c
index e23b8438c741651f48bbf529f89d0336cc718fed..c68a3b1e7409cb15879724d9acef1cecc97ab9fe 100644 (file)
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
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 d31887f9bf35a7fa9e31b1eb859a9cf21c918d6c..c0b781ae49af6cdc8a9bcc4a551310637366eb8f 100755 (executable)
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
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