git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: [PATCH] init: handle empty "template" parameter, was Re: fetch refspec foo/* matches foo*
Date: Mon, 28 Jul 2008 02:02:04 -0400	[thread overview]
Message-ID: <20080728060204.GC7294@sigill.intra.peff.net> (raw)
In-Reply-To: <alpine.DEB.1.00.0807261511490.26810@eeepc-johanness>

On Sat, Jul 26, 2008 at 03:13:26PM +0200, Johannes Schindelin wrote:

> > Also, while I have your attention, Junio, here is another bug fix
> > that should go into 1.6.0. I posted the patch as a "how about this" deep
> > in a thread and got no response (which means no complaints, right?).
> 
> Again it is in a thread...

Heh. Point taken.

My meaning was "you, Junio, did not see this because it was in another
thread, so I am pointing it out to you" but the irony of the rest of the
statement was lost on me during the original writing.

> I deem this patch obviously correct, and your reasoning as to what an 
> empty parameter should mean makes sense.

Thank you for reviewing, anyway. ;)

Here is a re-post with a test for the new behavior added in (and an
extra test just to make sure --template works at all. It does get used
by test-lib, so we were implicitly checking it to some degree, but it's
entirely possible that it could fail and the tests wouldn't necessarily
notice (e.g., if it accidentally used an installed set of templates
instead)).

-- >8 --
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."
---
 builtin-init-db.c |    2 ++
 t/t0001-init.sh   |   26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/builtin-init-db.c b/builtin-init-db.c
index 38b4fcb..baf0d09 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -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] != '/') {
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 2a38d98..620da5b 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
-- 
1.6.0.rc1.155.gd3310

  reply	other threads:[~2008-07-28  6:03 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-23 23:13 [PATCH] bash completion: Add completion for 'git help' Lee Marlow
2008-07-24  0:07 ` Lee Marlow
2008-07-25 20:40   ` Shawn O. Pearce
2008-07-25 21:02     ` Junio C Hamano
2008-07-26  8:24       ` fetch refspec foo/* matches foo* Jeff King
2008-07-26  8:33         ` Jeff King
2008-07-26 13:13           ` [PATCH] init: handle empty "template" parameter, was " Johannes Schindelin
2008-07-28  6:02             ` Jeff King [this message]
2008-07-28  6:13               ` Junio C Hamano
2008-07-28  6:16                 ` Jeff King
2008-07-27  0:18         ` Junio C Hamano
2008-07-27  6:15           ` [PATCH] make sure parsed wildcard refspec ends with slash Junio C Hamano
2008-07-27 17:20             ` Daniel Barkalow
2008-07-28  5:41             ` Jeff King
2008-07-24  0:08 ` [PATCH] bash completion: Add completion for 'git help' Lee Marlow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080728060204.GC7294@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).