Re: Document ability to disable template directory in git-init
- From
Todd Zullinger <tmz@pobox.com>
- Date
- Jul 4, 2025, 13:53 UTC
- Message-ID
- <aGfcyfJ0hkZ7kF7_@teonanacatl.net>
- In-Reply-To
- <boris.20250704123013@codesynthesis.com>
Boris Kolpackov wrote:
Show 11 quoted lines
> Han Young <hanyang.tony@bytedance.com> writes: > >> Digging through the changelog, I think the feature is added in v1.5.6.4: >> >> "git init --template=" with blank "template" parameter linked files >> under root directories to .git, which was a total nonsense. Instead, it >> means "I do not want to use anything from the template directory". > > Thanks for digging this up. So in a sense this is an obscurely- > documented behavior that people could reasonably choose to rely > upon. I think only more reason to document this more prominently.
The commit which added it, d65d2b2fb4 (init: handle empty "template" parameter, 2008-07-28), notes the behavior:
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."It was released in 1.5.6.5, just in case anyone is looking at the release notes for 1.5.6.4 and wondering why this isn't mentioned. :)
It came up in <20080722200911.GA3097@sigill.intra.peff.net> on the list.
It's been this way for 17 years and seems unlikely to change. Documenting it ought to be a good thing.
I think that may fit best in the TEMPLATE DIRECTORY section of Documentation/git-init.adoc, if anyone here is interested in taking a stab at a patch.
You'd probably want to confirm how git init behaves when `init.templatedir` and `GIT_TEMPLATE_DIR` are set to empty values as well, to document the effects fully and save a future user wondering why the docs mention --template= and not init.templatedir or GIT_TEMPLATE_DIR.
If they all behave the same (which I believe they do), the docs could just say an empty value causes no templates to be copied, without listing each of the methods by which it might be set.
-- Todd