{"thread":{"id":"39609","subject":"git init with template dir","startedAt":"2015-06-12T07:09:18Z","lastAt":"2015-06-12T16:13:16Z","messageCount":4,"participants":["Alex Cornejo","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"263651","messageId":"loom.20150612T085835-977@post.gmane.org","threadId":"39609","inReplyTo":null,"subject":"git init with template dir","fromName":"Alex Cornejo","fromEmail":"acornejo@gmail.com","sentAt":"2015-06-12T07:09:18Z","receivedAt":"2015-06-12T07:09:18Z","isPatch":false,"sender":{"key":"acornejo@gmail.com","avatar":null},"body":"I was surprised to see that when using git-init, if the template folder\nis itself a symlink, then the contents of the template is NOT copied to\nthe resulting git repository, but instead each individual file is\nsymlinked.\n\nFor my particular use case, this is undesirable (since if I am not\ncareful, then when I change the hook of one git repo, it\nactually changes the hooks of all other repos too). It is easy\nenough for me to work around this (i.e. by instead pointing my gitconfig\nto use a template dir which is not a symlink), but I was\nwondering weather this is a feature folks use (and for what end), or if\nthis is unintended behavior.\n\nFurthermore, would a patch be welcome that either disables this\nfeature through an option (or perhaps permanently by just copying the\ncontents of the symlinked folder instead of creating individual\nsymlinks), or am I the only git user that was surprised by this\nbehavior and wanted to disable it?\n\n- Alex\n"},{"id":"263668","messageId":"xmqqioatdk0z.fsf@gitster.dls.corp.google.com","threadId":"39609","inReplyTo":"loom.20150612T085835-977@post.gmane.org","subject":"Re: git init with template dir","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-06-12T15:27:24Z","receivedAt":"2015-06-12T15:27:24Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alex Cornejo <acornejo@gmail.com> writes:\n\n> I was surprised to see that when using git-init, if the template folder\n> is itself a symlink, then the contents of the template is NOT copied to\n> the resulting git repository, but instead each individual file is\n> symlinked.\n\nHmmm, I do not seem to be able to do this, though.\n\n        $ ln -s $HOME/g/share/git-core/templates /var/tmp/git-template\n        $ cd /var/tmp\n\t$ git init --template=/var/tmp/git-template new\n        $ find new/.git -type l\n        ... nothing ...\n\n> For my particular use case, this is undesirable (since if I am not\n> careful, then when I change the hook of one git repo, it\n> actually changes the hooks of all other repos too). It is easy\n> enough for me to work around this (i.e. by instead pointing my gitconfig\n> to use a template dir which is not a symlink), but I was\n> wondering weather this is a feature folks use (and for what end), or if\n> this is unintended behavior.\n\nThat you had to predicate \"this is undesireable\" with \"For my\nparticular use case\" tells me that other people may want to see that\nthese things shared and automatically receive updates when the\noriginals in the temporate directory are updated, which makes it\nsound like a \"feature\" not an \"unintended behaviour\", at least to\nme.\n"},{"id":"263670","messageId":"loom.20150612T175402-182@post.gmane.org","threadId":"39609","inReplyTo":"xmqqioatdk0z.fsf@gitster.dls.corp.google.com","subject":"Re: git init with template dir","fromName":"Alex Cornejo","fromEmail":"acornejo@gmail.com","sentAt":"2015-06-12T15:59:51Z","receivedAt":"2015-06-12T15:59:51Z","isPatch":false,"sender":{"key":"acornejo@gmail.com","avatar":null},"body":"Junio C Hamano <gitster <at> pobox.com> writes:\n\n> Hmmm, I do not seem to be able to do this, though.\n> \n>         $ ln -s $HOME/g/share/git-core/templates /var/tmp/git-template\n>         $ cd /var/tmp\n> \t$ git init --template=/var/tmp/git-template new\n>         $ find new/.git -type l\n>         ... nothing ...\n\nThanks for your prompt response Juno.\n\nThat make sense. The fact that you were unable to reproduce this tells\nme that there is probably something fishy/unexpected with the\nenvironment in which I tried this (which is not too surprising, given\nthat I was doing it inside a linux container, inside a virtual machine,\nwhere both of these were setup using a scripts which ultimately failed\nafter the git init step, due to the symlink behavior I described, but\nmost likely this is my own fault). I should have tried to reproduce this\non a clean slate before posting this question.\n\nThanks again,\n\nAlex\n"},{"id":"263671","messageId":"xmqqeglgewgz.fsf@gitster.dls.corp.google.com","threadId":"39609","inReplyTo":"loom.20150612T175402-182@post.gmane.org","subject":"Re: git init with template dir","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-06-12T16:13:16Z","receivedAt":"2015-06-12T16:13:16Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alex Cornejo <acornejo@gmail.com> writes:\n\n> Junio C Hamano <gitster <at> pobox.com> writes:\n>\n>> Hmmm, I do not seem to be able to do this, though.\n>> \n>>         $ ln -s $HOME/g/share/git-core/templates /var/tmp/git-template\n>>         $ cd /var/tmp\n>>         $ git init --template=/var/tmp/git-template new\n>>         $ find new/.git -type l\n>>         ... nothing ...\n>\n> Thanks for your prompt response Juno.\n>\n> That make sense. The fact that you were unable to reproduce this tells\n> me that there is probably something fishy/unexpected with the\n> environment in which I tried this (which is not too surprising, given\n> that I was doing it inside a linux container, inside a virtual machine,\n> where both of these were setup using a scripts which ultimately failed\n> after the git init step, due to the symlink behavior I described, but\n> most likely this is my own fault).\n\nI wouldn't call that your \"fault\".  After all, as more people want\nto run Git in different environments, we would want to make sure Git\nruns correctly for them.\n\nI quickly re-scanned what we do inside \"git init\" and how we\npopulate the repository from templates.  This happens all in\nbuiltin/init-db.c:\n\n - copy_templates() does opendir(), so it should not have mattered\n   that I used /var/tmp/git-template that is a symbolic link to a\n   real location in my quick reproduction attempt;\n\n - it calls a recursive copy_templates_1() with that directory\n   handle it opened for the template directory.  Each entry it finds\n   are inspected and\n\n   - real directories are recursed into;\n   - files are copied; and\n   - symlinks are recreated.\n\nSo if I instead made a new directory /var/tmp/git-template/ and then\npopulated it with a bunch of symbolic links e.g. hooks, description,\netc., that points at their real location, I would have seen that the\nresulting repository populated with symbolic links.\n\nAnd I think that is an expected behaviour.\n\nBut if \"git init\" made bunch of symbolic links only because it was\ngiven a symbolic link to the real directory via its --template\nparameter, that _is_ unexpected, and we may want to dig deeper to\ncorrect it.\n"}]}