{"thread":{"id":"63738","subject":"Document ability to disable template directory in git-init","startedAt":"2025-07-03T14:49:37Z","lastAt":"2025-07-06T03:30:55Z","messageCount":7,"participants":["Boris Kolpackov","Han Young","Todd Zullinger","Kristoffer Haugsbakk","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"521278","messageId":"boris.20250703161436@codesynthesis.com","threadId":"63738","inReplyTo":null,"subject":"Document ability to disable template directory in git-init","fromName":"Boris Kolpackov","fromEmail":"boris@codesynthesis.com","sentAt":"2025-07-03T14:40:02Z","receivedAt":"2025-07-03T14:49:37Z","isPatch":false,"sender":{"key":"boris@codesynthesis.com","avatar":null},"body":"Hello,\n\nLooking at the git-init(1) man page, there doesn't appear to be a way\nto disable copying the contents of the default template directory, other\nthan passing a path pointing to an empty directory.\n\nHowever, if one passes an empty path, for example with the --template\noption, then git does not complain and does not copy anything:\n\ngit init --template=\n\nLooking at the code, this undocumented (AFAICS) behavior appears to\nbe there at least from git 2.1:\n\n\nstatic void copy_templates(const char *template_dir)\n{\n\t...\n\n\tif (!template_dir)\n\t\ttemplate_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);\n\tif (!template_dir)\n\t\ttemplate_dir = init_db_template_dir;\n\tif (!template_dir)\n\t\ttemplate_dir = system_path(DEFAULT_GIT_TEMPLATE_DIR);\n\tif (!template_dir[0])\n\t\treturn;\n\n\nFor reference, the corresponding code in 2.50:\n\n\nstatic void copy_templates(const char *option_template)\n{\n\tconst char *template_dir = get_template_dir(option_template);\n\t\n\t...\n\n\tif (!template_dir || !*template_dir)\n\t\treturn;\n\n\nI would like to suggest that we document this behavior so that it can\nbe relied upon. The motivation for omitting the default template are\nrepositories created by tools, such as package managers, for the sole\npurpose of fetching some information from remotes. In this case all\nthe stuff copied from the template (such as hooks) is an unnecessary\nwaste of time and space.\n\nLooking at the git-init(1) man page, the TEMPLATE DIRECTORY section\nseems like the natural place to document this semantics. For example,\nwe could add the following sentence after the list of all the places\nwhere the template directory can be specified:\n\n\"If the specified template directory is an empty path (for example,\n--template=), then no template will be copied.\"\n\nLet me know what you think.\n\n\nThanks,\nBoris\n"},{"id":"521291","messageId":"CAG1j3zEiD341X-_ZdR2puaEmZZ0ZBWSmyboyyGZaDXcDTcmAeA@mail.gmail.com","threadId":"63738","inReplyTo":"boris.20250703161436@codesynthesis.com","subject":"Re: [External] Document ability to disable template directory in git-init","fromName":"Han Young","fromEmail":"hanyang.tony@bytedance.com","sentAt":"2025-07-04T02:49:08Z","receivedAt":"2025-07-04T02:49:20Z","isPatch":false,"sender":{"key":"hanyang.tony@bytedance.com","avatar":"https://avatars.githubusercontent.com/u/108711387?v=4"},"body":"On Thu, Jul 3, 2025 at 10:51 PM Boris Kolpackov <boris@codesynthesis.com> wrote:\n> Looking at the code, this undocumented (AFAICS) behavior appears to\n> be there at least from git 2.1:\n\nDigging through the changelog, I think the feature is added in v1.5.6.4:\n\n \"git init --template=\" with blank \"template\" parameter linked files\n under root directories to .git, which was a total nonsense.  Instead, it\n means \"I do not want to use anything from the template directory\".\n\n> I would like to suggest that we document this behavior so that it can\n> be relied upon. The motivation for omitting the default template are\n> repositories created by tools, such as package managers, for the sole\n> purpose of fetching some information from remotes. In this case all\n> the stuff copied from the template (such as hooks) is an unnecessary\n> waste of time and space.\nI've seen some package managers pass \"--template=\" to git-clone, I'd\nsay this is a widely used undocumented feature :P\nDocument the behavior would help people understand the existing\nusages of --template=\n\nThanks.\n"},{"id":"521304","messageId":"boris.20250704123013@codesynthesis.com","threadId":"63738","inReplyTo":"CAG1j3zEiD341X-_ZdR2puaEmZZ0ZBWSmyboyyGZaDXcDTcmAeA@mail.gmail.com","subject":"Re: [External] Document ability to disable template directory in git-init","fromName":"Boris Kolpackov","fromEmail":"boris@codesynthesis.com","sentAt":"2025-07-04T10:33:31Z","receivedAt":"2025-07-04T10:33:38Z","isPatch":false,"sender":{"key":"boris@codesynthesis.com","avatar":null},"body":"Han Young <hanyang.tony@bytedance.com> writes:\n\n> Digging through the changelog, I think the feature is added in v1.5.6.4:\n> \n>  \"git init --template=\" with blank \"template\" parameter linked files\n>  under root directories to .git, which was a total nonsense.  Instead, it\n>  means \"I do not want to use anything from the template directory\".\n\nThanks for digging this up. So in a sense this is an obscurely-\ndocumented behavior that people could reasonably choose to rely\nupon. I think only more reason to document this more prominently.\n\n"},{"id":"521320","messageId":"aGfcyfJ0hkZ7kF7_@teonanacatl.net","threadId":"63738","inReplyTo":"boris.20250704123013@codesynthesis.com","subject":"Re: Document ability to disable template directory in git-init","fromName":"Todd Zullinger","fromEmail":"tmz@pobox.com","sentAt":"2025-07-04T13:53:13Z","receivedAt":"2025-07-04T13:53:18Z","isPatch":false,"sender":{"key":"tmz@pobox.com","avatar":"https://avatars.githubusercontent.com/u/806319?v=4"},"body":"Boris Kolpackov wrote:\n> Han Young <hanyang.tony@bytedance.com> writes:\n> \n>> Digging through the changelog, I think the feature is added in v1.5.6.4:\n>> \n>>  \"git init --template=\" with blank \"template\" parameter linked files\n>>  under root directories to .git, which was a total nonsense.  Instead, it\n>>  means \"I do not want to use anything from the template directory\".\n> \n> Thanks for digging this up. So in a sense this is an obscurely-\n> documented behavior that people could reasonably choose to rely\n> upon. I think only more reason to document this more prominently.\n\nThe commit which added it, d65d2b2fb4 (init: handle empty\n\"template\" parameter, 2008-07-28), notes the behavior:\n\n    init: handle empty \"template\" parameter\n    \n    If a user passes \"--template=\", then our template parameter\n    is blank. Unfortunately, copy_templates() assumes it has at\n    least one character, and does all sorts of bad things like\n    reading from template[-1] and then proceeding to link all of\n    '/' into the .git directory.\n    \n    This patch just checks for that condition in copy_templates\n    and aborts. As a side effect, this means that --template=\n    now has the meaning \"don't copy any templates.\"\n\nIt was released in 1.5.6.5, just in case anyone is looking\nat the release notes for 1.5.6.4 and wondering why this\nisn't mentioned. :)\n\nIt came up in <20080722200911.GA3097@sigill.intra.peff.net>\non the list.\n\nIt's been this way for 17 years and seems unlikely to\nchange.  Documenting it ought to be a good thing.\n\nI think that may fit best in the TEMPLATE DIRECTORY section\nof Documentation/git-init.adoc, if anyone here is interested\nin taking a stab at a patch.\n\nYou'd probably want to confirm how git init behaves when\n`init.templatedir` and `GIT_TEMPLATE_DIR` are set to empty\nvalues as well, to document the effects fully and save a\nfuture user wondering why the docs mention --template= and\nnot init.templatedir or GIT_TEMPLATE_DIR.\n\nIf they all behave the same (which I believe they do), the\ndocs could just say an empty value causes no templates to be\ncopied, without listing each of the methods by which it\nmight be set.\n\n-- \nTodd\n"},{"id":"521327","messageId":"c20e2e7b-8471-4398-9bfb-6534f8ad2b39@app.fastmail.com","threadId":"63738","inReplyTo":"boris.20250703161436@codesynthesis.com","subject":"Re: Document ability to disable template directory in git-init","fromName":"Kristoffer Haugsbakk","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2025-07-04T14:57:25Z","receivedAt":"2025-07-04T14:57:46Z","isPatch":false,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"On Thu, Jul 3, 2025, at 16:40, Boris Kolpackov wrote:\n> Hello,\n>\n> Looking at the git-init(1) man page, there doesn't appear to be a way\n> to disable copying the contents of the default template directory, other\n> than passing a path pointing to an empty directory.\n>\n> However, if one passes an empty path, for example with the --template\n> option, then git does not complain and does not copy anything:\n>\n> git init --template=\n>\n> Looking at the code, this undocumented (AFAICS) behavior appears to\n> be there at least from git 2.1:\n>\n>\n> static void copy_templates(const char *template_dir)\n> {\n> \t...\n>\n> \tif (!template_dir)\n> \t\ttemplate_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);\n> \tif (!template_dir)\n> \t\ttemplate_dir = init_db_template_dir;\n> \tif (!template_dir)\n> \t\ttemplate_dir = system_path(DEFAULT_GIT_TEMPLATE_DIR);\n> \tif (!template_dir[0])\n> \t\treturn;\n>\n>\n> For reference, the corresponding code in 2.50:\n>\n>\n> static void copy_templates(const char *option_template)\n> {\n> \tconst char *template_dir = get_template_dir(option_template);\n>\t\n> \t...\n>\n> \tif (!template_dir || !*template_dir)\n> \t\treturn;\n>\n>\n> I would like to suggest that we document this behavior so that it can\n> be relied upon. The motivation for omitting the default template are\n> repositories created by tools, such as package managers, for the sole\n> purpose of fetching some information from remotes. In this case all\n> the stuff copied from the template (such as hooks) is an unnecessary\n> waste of time and space.\n>\n> Looking at the git-init(1) man page, the TEMPLATE DIRECTORY section\n> seems like the natural place to document this semantics. For example,\n> we could add the following sentence after the list of all the places\n> where the template directory can be specified:\n>\n> \"If the specified template directory is an empty path (for example,\n> --template=), then no template will be copied.\"\n>\n> Let me know what you think.\n>\n>\n> Thanks,\n> Boris\n\nYou can apparently pass `--no-templates`\n\n```\ngit init --template=$HOME/git-template --no-templates\n```\n\nI had a distinct `description` in the template directory.  That was not\nused in the above.\n"},{"id":"521329","messageId":"ecb6df31-1f3a-4373-91ed-ae5231af7f7e@app.fastmail.com","threadId":"63738","inReplyTo":"c20e2e7b-8471-4398-9bfb-6534f8ad2b39@app.fastmail.com","subject":"Re: Document ability to disable template directory in git-init","fromName":"Kristoffer Haugsbakk","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2025-07-04T15:17:52Z","receivedAt":"2025-07-04T15:18:14Z","isPatch":false,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"On Fri, Jul 4, 2025, at 16:57, Kristoffer Haugsbakk wrote:\n> You can apparently pass `--no-templates`\n>\n> ```\n> git init --template=$HOME/git-template --no-templates\n> ```\n\nTypo:\n\n```\ngit init --template=$HOME/git-template --no-template\n````\n"},{"id":"521354","messageId":"20250706033054.GC3041790@coredump.intra.peff.net","threadId":"63738","inReplyTo":"aGfcyfJ0hkZ7kF7_@teonanacatl.net","subject":"Re: Document ability to disable template directory in git-init","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2025-07-06T03:30:54Z","receivedAt":"2025-07-06T03:30:55Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Jul 04, 2025 at 09:53:13AM -0400, Todd Zullinger wrote:\n\n> > Thanks for digging this up. So in a sense this is an obscurely-\n> > documented behavior that people could reasonably choose to rely\n> > upon. I think only more reason to document this more prominently.\n> \n> The commit which added it, d65d2b2fb4 (init: handle empty\n> \"template\" parameter, 2008-07-28), notes the behavior:\n> \n>     init: handle empty \"template\" parameter\n>     \n>     If a user passes \"--template=\", then our template parameter\n>     is blank. Unfortunately, copy_templates() assumes it has at\n>     least one character, and does all sorts of bad things like\n>     reading from template[-1] and then proceeding to link all of\n>     '/' into the .git directory.\n>     \n>     This patch just checks for that condition in copy_templates\n>     and aborts. As a side effect, this means that --template=\n>     now has the meaning \"don't copy any templates.\"\n> \n> It was released in 1.5.6.5, just in case anyone is looking\n> at the release notes for 1.5.6.4 and wondering why this\n> isn't mentioned. :)\n> \n> It came up in <20080722200911.GA3097@sigill.intra.peff.net>\n> on the list.\n> \n> It's been this way for 17 years and seems unlikely to\n> change.  Documenting it ought to be a good thing.\n\nOops, I suppose this is my fault. I agree that this is the intended\nbehavior, and probably ought to be documented.\n\nHowever, as Kristoffer mentioned, \"--no-template\" should work in the\nsame way and is IMHO a bit more ergonomic. It didn't exist back when\nthat commit was made (we weren't using parse-options yet).\n\nSo perhaps the documentation for --template ought to point people in\nthat direction. But probably we should still mention the \"empty string\"\nbehavior in all of the other spots, since as you mentioned it works\nequally for the config and environment variables (where is no \"--no-\"\nequivalent).\n\n-Peff\n"}]}