{"thread":{"id":"12813","subject":"Store autocrlf during init-db (was [msysGit] autocrlf problems with Git-preview20080301.exe)","startedAt":"2008-03-23T09:31:36Z","lastAt":"2008-03-25T09:55:19Z","messageCount":25,"participants":["Steffen Prohaska","Johannes Schindelin","Dmitry Potapov","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"72725","messageId":"alpine.OSX.1.00.0803230943500.7541@cougar","threadId":"12813","inReplyTo":"alpine.LSU.1.00.0803230310500.4353@racer.site","subject":"Store autocrlf during init-db (was [msysGit] autocrlf problems with Git-preview20080301.exe)","fromName":"Steffen Prohaska","fromEmail":"prohaska@zib.de","sentAt":"2008-03-23T09:31:36Z","receivedAt":"2008-03-23T09:31:36Z","isPatch":false,"sender":{"key":"prohaska@zib.de","avatar":"https://avatars.githubusercontent.com/u/217580?v=4"},"body":"\nOn Sun, 23 Mar 2008, Johannes Schindelin wrote:\n\n> On Sat, 22 Mar 2008, Junio C Hamano wrote:\n> \n> > \n> > Steffen Prohaska <prohaska@zib.de> writes:\n> > \n> > >> I suppose autocrlf enabled by default could be useful for new \n> > >> repositories, but not for working with existing repositories.\n> > >\n> > > We changed the global default to a sane setting for cross-platform \n> > > projects to avoid such problems in the future.  This means that from \n> > > now on git will take care that any repository newly created will have \n> > > sane line endings (LF in the repository; and CRLF in the work tree if \n> > > checked out on Windows respectively LF if checked out on Unix).\n> > \n> > I've always wondered why you guys used /etc/gitconfig instead of setting \n> > it in the templates (or a patch to git-init).\n> > \n> > I was against the idea of /etc/gitconfig from the very beginning (even \n> > before msysgit existed) in git.git itself, but this is a very good \n> > example why /etc/gitconfig is a bad idea.  It affects _existing_ setups.\n> > \n> > How about fixing msys port so that it sets the configuration when the \n> > user initializes a _new_ repository, without breaking repositories the \n> > user has been happily using?\n> \n> Makes sense.\n\nHmm.  I am not convinced.\n\nSetting autocrlf for every repository limits the user's options to\noverride the default.  Currently we provide a global default and the\nuser can either override globally for all his repositories or on\na per-repository basis.  Hence, users can decide that they want autocrlf\nto never happen and can easily set this in ~/.gitconfig.  If we stored\nautocrlf in every newly created repository, the user would need to\noverride our default again and again for every new repository.\n\nMaybe what we want is to conserve the setup that exists when a new\nrepository is created.  Changing autocrlf later is tricky because the\nwork tree's line endings depend on the settings during checkout.\nTherefore, it makes sense to preserve the value of autocrlf that exists\nduring the first checkout.  In this regards autocrlf is different from,\nfor example, author because author can be easily changed later without\nrequiring any conversion of existing files in the work tree.\n\nPatch follows.\n\nUnfortunately the proposed change won't change the fact that existing\nmsysgit setups still break.  I still do not see an easy way to avoid\nthis.\n\n            Steffen\n"},{"id":"72726","messageId":"alpine.OSX.1.00.0803231032180.7541@cougar","threadId":"12813","inReplyTo":"alpine.OSX.1.00.0803230943500.7541@cougar","subject":"[PATCH] init-db: Store current value of autocrlf","fromName":"Steffen Prohaska","fromEmail":"prohaska@zib.de","sentAt":"2008-03-23T09:34:13Z","receivedAt":"2008-03-23T09:34:13Z","isPatch":true,"sender":{"key":"prohaska@zib.de","avatar":"https://avatars.githubusercontent.com/u/217580?v=4"},"body":"\nStoring the current value of autocrlf to preserve it for this repository\neven if the global setup changes is a good idea.  Changing autocrlf\nlater is tricky because the work tree's line endings depend on the\nsettings during checkout.  Therefore, it makes sense to preserve the\nvalue of autocrlf that exists during the first checkout.  In this\nregards autocrlf is different from, for example, author, because author\ncan be easily changed later without requiring any conversion of existing\nfiles in the work tree.\n\nThis commit modifies the initialization of a new repository to store the\ncurrent value of autocrlf.\n\nSigned-off-by: Steffen Prohaska <prohaska@zib.de>\n---\n builtin-init-db.c |   16 ++++++++++++++++\n 1 files changed, 16 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex 79eaf8d..6c49a82 100644\n--- a/builtin-init-db.c\n+++ b/builtin-init-db.c\n@@ -268,6 +268,22 @@ static int create_default_files(const char *git_dir, const char *template_path)\n \t\t\tgit_config_set(\"core.symlinks\", \"false\");\n \t}\n \n+\t/*\n+\t *  Store current value of auto_crlf to preserve it for\n+\t *  this repository even if the global setup changes.\n+\t */\n+\tswitch (auto_crlf) {\n+\tcase -1:\n+\t\tgit_config_set(\"core.autocrlf\", \"input\");\n+\t\tbreak;\n+\tcase 0:\n+\t\tgit_config_set(\"core.autocrlf\", \"false\");\n+\t\tbreak;\n+\tcase 1:\n+\t\tgit_config_set(\"core.autocrlf\", \"true\");\n+\t\tbreak;\n+\t}\n+\n \treturn reinit;\n }\n \n-- \n1.5.5.rc0.21.g740fd.dirty\n"},{"id":"72732","messageId":"alpine.LSU.1.00.0803231200010.4353@racer.site","threadId":"12813","inReplyTo":"alpine.OSX.1.00.0803230943500.7541@cougar","subject":"Re: Store autocrlf during init-db (was [msysGit] autocrlf problems with Git-preview20080301.exe)","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-23T11:01:08Z","receivedAt":"2008-03-23T11:01:08Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nHi,\n\nOn Sun, 23 Mar 2008, Steffen Prohaska wrote:\n\n> On Sun, 23 Mar 2008, Johannes Schindelin wrote:\n> \n> > On Sat, 22 Mar 2008, Junio C Hamano wrote:\n> > \n> > > \n> > > Steffen Prohaska <prohaska@zib.de> writes:\n> > > \n> > > >> I suppose autocrlf enabled by default could be useful for new \n> > > >> repositories, but not for working with existing repositories.\n> > > >\n> > > > We changed the global default to a sane setting for cross-platform \n> > > > projects to avoid such problems in the future.  This means that \n> > > > from now on git will take care that any repository newly created \n> > > > will have sane line endings (LF in the repository; and CRLF in the \n> > > > work tree if checked out on Windows respectively LF if checked out \n> > > > on Unix).\n> > > \n> > > I've always wondered why you guys used /etc/gitconfig instead of \n> > > setting it in the templates (or a patch to git-init).\n> > > \n> > > I was against the idea of /etc/gitconfig from the very beginning \n> > > (even before msysgit existed) in git.git itself, but this is a very \n> > > good example why /etc/gitconfig is a bad idea.  It affects \n> > > _existing_ setups.\n> > > \n> > > How about fixing msys port so that it sets the configuration when \n> > > the user initializes a _new_ repository, without breaking \n> > > repositories the user has been happily using?\n> > \n> > Makes sense.\n> \n> Hmm.  I am not convinced.\n> \n> Setting autocrlf for every repository limits the user's options to\n> override the default.\n\nThen maybe a way for the user to override the global templates is what we \nneed?  I can see that this would be useful outside of the crlf issue.\n\nCiao,\nDscho\n"},{"id":"72737","messageId":"alpine.OSX.1.00.0803231326290.11994@cougar","threadId":"12813","inReplyTo":"alpine.LSU.1.00.0803231200010.4353@racer.site","subject":"Re: Store autocrlf during init-db (was [msysGit] autocrlf problems with Git-preview20080301.exe)","fromName":"Steffen Prohaska","fromEmail":"prohaska@zib.de","sentAt":"2008-03-23T12:30:59Z","receivedAt":"2008-03-23T12:30:59Z","isPatch":false,"sender":{"key":"prohaska@zib.de","avatar":"https://avatars.githubusercontent.com/u/217580?v=4"},"body":"\nOn Sun, 23 Mar 2008, Johannes Schindelin wrote:\n\n> On Sun, 23 Mar 2008, Steffen Prohaska wrote:\n> \n> > On Sun, 23 Mar 2008, Johannes Schindelin wrote:\n> > \n> > Setting autocrlf for every repository limits the user's options to\n> > override the default.\n> \n> Then maybe a way for the user to override the global templates is what we \n> need?  I can see that this would be useful outside of the crlf issue.\n\nI do not think we need this.  autocrlf is a configurable variable and we\nalready have a mechanism for the user to override configuration\nvariables.  The user can use \"git config --global ...\" to sets his\npreferences.  This mechanism is well established.  I do not see a reason\nnot to use it.\n\n            Steffen\n"},{"id":"72741","messageId":"alpine.LSU.1.00.0803231404390.4353@racer.site","threadId":"12813","inReplyTo":"alpine.OSX.1.00.0803231326290.11994@cougar","subject":"Re: [msysGit] Re: Store autocrlf during init-db (was [msysGit] autocrlf problems with Git-preview20080301.exe)","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-23T13:05:59Z","receivedAt":"2008-03-23T13:05:59Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 23 Mar 2008, Steffen Prohaska wrote:\n\n> On Sun, 23 Mar 2008, Johannes Schindelin wrote:\n> \n> > On Sun, 23 Mar 2008, Steffen Prohaska wrote:\n> > \n> > > On Sun, 23 Mar 2008, Johannes Schindelin wrote:\n> > > \n> > > Setting autocrlf for every repository limits the user's options to\n> > > override the default.\n> > \n> > Then maybe a way for the user to override the global templates is what we \n> > need?  I can see that this would be useful outside of the crlf issue.\n> \n> I do not think we need this.  autocrlf is a configurable variable and we \n> already have a mechanism for the user to override configuration \n> variables.  The user can use \"git config --global ...\" to sets his \n> preferences.  This mechanism is well established.  I do not see a reason \n> not to use it.\n\nThe point is: if we use /etc/gitconfig, we also touch _existing_ setups \n(as Junio pointed out).  Which, in the case of autocrlf, is not desirable.\n\nAnd if we go the route via templates, $HOME/.gitconfig will do no good, as \nthe configuration in the repository trumps the --global configuration.\n\nCiao,\nDscho\n"},{"id":"72746","messageId":"alpine.OSX.1.00.0803231428220.13789@cougar","threadId":"12813","inReplyTo":"alpine.LSU.1.00.0803231404390.4353@racer.site","subject":"Re: Store autocrlf during init-db (was [msysGit] autocrlf problems with Git-preview20080301.exe)","fromName":"Steffen Prohaska","fromEmail":"prohaska@zib.de","sentAt":"2008-03-23T13:42:16Z","receivedAt":"2008-03-23T13:42:16Z","isPatch":false,"sender":{"key":"prohaska@zib.de","avatar":"https://avatars.githubusercontent.com/u/217580?v=4"},"body":"\nOn Sun, 23 Mar 2008, Johannes Schindelin wrote:\n\n> On Sun, 23 Mar 2008, Steffen Prohaska wrote:\n> \n> > On Sun, 23 Mar 2008, Johannes Schindelin wrote:\n> > \n> > > On Sun, 23 Mar 2008, Steffen Prohaska wrote:\n> > > \n> > > > On Sun, 23 Mar 2008, Johannes Schindelin wrote:\n> > > > \n> > > > Setting autocrlf for every repository limits the user's options to\n> > > > override the default.\n> > > \n> > > Then maybe a way for the user to override the global templates is what we \n> > > need?  I can see that this would be useful outside of the crlf issue.\n> > \n> > I do not think we need this.  autocrlf is a configurable variable and we \n> > already have a mechanism for the user to override configuration \n> > variables.  The user can use \"git config --global ...\" to sets his \n> > preferences.  This mechanism is well established.  I do not see a reason \n> > not to use it.\n> \n> The point is: if we use /etc/gitconfig, we also touch _existing_ setups \n> (as Junio pointed out).  Which, in the case of autocrlf, is not desirable.\n\nI proposed a mechanism that would avoid such problems in the future.\nRepositories that would copy the current setting of autocrlf to their\nlocal .git/config would be shielded from future changes to the global\nsetup.\n\n\n> And if we go the route via templates, $HOME/.gitconfig will do no good, as \n> the configuration in the repository trumps the --global configuration.\n\nWe have two conflicting objectives and I do not know how to meet them\nthe same time:\n\n 1) Existing setups should not break.\n\n 2) Users should have a way to set a global default for autocrlf that\n    overrides our defaults.\n\nIf we store the new default in newly created repositories, (1) would be\nmet but (2) is not possible.  If we support ~/.gitconfig for overriding\nthe system-wide default, (2) is trivial but (1) is hard to meet.\n\nI propose to break existing setup and provide a simple mechanism to\navoid such breakages in the future.  As you pointed out earlier we are\nstill only releasing \"previews\" on Windows and one reason for this\ndecision was the lacking support for autocrlf.  We always knew that some\nwork would be needed before we have a sane setup on Windows.\n\nMaybe we can improve the installer to warn the users that the default\nhas changed and existing repositories must either be converted or the\nglobal default must be overridden.  The installer could ask the user to\nconfirm this change.  Maybe this is sufficient to avoid further\ncomplains about weird behavior after upgrading.\n\n            Steffen\n"},{"id":"72754","messageId":"alpine.LSU.1.00.0803231506000.4353@racer.site","threadId":"12813","inReplyTo":"alpine.OSX.1.00.0803231428220.13789@cougar","subject":"Re: [msysGit] Re: Store autocrlf during init-db (was [msysGit] autocrlf problems with Git-preview20080301.exe)","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-23T14:07:28Z","receivedAt":"2008-03-23T14:07:28Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 23 Mar 2008, Steffen Prohaska wrote:\n\n> On Sun, 23 Mar 2008, Johannes Schindelin wrote:\n> \n> > The point is: if we use /etc/gitconfig, we also touch _existing_ \n> > setups (as Junio pointed out).  Which, in the case of autocrlf, is not \n> > desirable.\n> \n> I proposed a mechanism that would avoid such problems in the future.\n\nYes, but your solution feels a bit limited and \"hot-needled\" for just one \npurpose.\n\n> Maybe we can improve the installer to warn the users that the default \n> has changed and existing repositories must either be converted or the \n> global default must be overridden.  The installer could ask the user to \n> confirm this change.  Maybe this is sufficient to avoid further \n> complains about weird behavior after upgrading.\n\nMaybe.  My experience is that people do not even read the big red warnings \nin the installer.  Whatever.\n\nCiao,\nDscho\n"},{"id":"72773","messageId":"alpine.OSX.1.00.0803231643040.16879@cougar","threadId":"12813","inReplyTo":"alpine.LSU.1.00.0803231506000.4353@racer.site","subject":"Re: Store autocrlf during init-db (was [msysGit] autocrlf problems with Git-preview20080301.exe)","fromName":"Steffen Prohaska","fromEmail":"prohaska@zib.de","sentAt":"2008-03-23T15:50:27Z","receivedAt":"2008-03-23T15:50:27Z","isPatch":false,"sender":{"key":"prohaska@zib.de","avatar":"https://avatars.githubusercontent.com/u/217580?v=4"},"body":"\nOn Sun, 23 Mar 2008, Johannes Schindelin wrote:\n\n> On Sun, 23 Mar 2008, Steffen Prohaska wrote:\n> \n> > On Sun, 23 Mar 2008, Johannes Schindelin wrote:\n> > \n> > > The point is: if we use /etc/gitconfig, we also touch _existing_ \n> > > setups (as Junio pointed out).  Which, in the case of autocrlf, is not \n> > > desirable.\n> > \n> > I proposed a mechanism that would avoid such problems in the future.\n> \n> Yes, but your solution feels a bit limited and \"hot-needled\" for just one \n> purpose.\n\nWhat limits do you mean (except that it does still break existing\nmsysgit setups; but would avoid this problem in the future)?\n\n            Steffen\n"},{"id":"72777","messageId":"alpine.LSU.1.00.0803231734190.4353@racer.site","threadId":"12813","inReplyTo":"alpine.OSX.1.00.0803231643040.16879@cougar","subject":"Re: Store autocrlf during init-db (was [msysGit] autocrlf problems with Git-preview20080301.exe)","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-23T16:35:13Z","receivedAt":"2008-03-23T16:35:13Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nHi,\n\nOn Sun, 23 Mar 2008, Steffen Prohaska wrote:\n\n> On Sun, 23 Mar 2008, Johannes Schindelin wrote:\n> \n> > On Sun, 23 Mar 2008, Steffen Prohaska wrote:\n> > \n> > > On Sun, 23 Mar 2008, Johannes Schindelin wrote:\n> > > \n> > > > The point is: if we use /etc/gitconfig, we also touch _existing_ \n> > > > setups (as Junio pointed out).  Which, in the case of autocrlf, is \n> > > > not desirable.\n> > > \n> > > I proposed a mechanism that would avoid such problems in the future.\n> > \n> > Yes, but your solution feels a bit limited and \"hot-needled\" for just \n> > one purpose.\n> \n> What limits do you mean (except that it does still break existing \n> msysgit setups; but would avoid this problem in the future)?\n\nI have the impression that a problem just like this will arise again, just \nnot with corelf, but with another setting that the admin might want to \nset per default in git-init, but the user might want to override.\n\nCiao,\nDscho\n"},{"id":"72827","messageId":"alpine.OSX.1.00.0803232237400.19285@cougar","threadId":"12813","inReplyTo":"alpine.LSU.1.00.0803231734190.4353@racer.site","subject":"Re: Store autocrlf during init-db (was [msysGit] autocrlf problems with Git-preview20080301.exe)","fromName":"Steffen Prohaska","fromEmail":"prohaska@zib.de","sentAt":"2008-03-23T22:53:13Z","receivedAt":"2008-03-23T22:53:13Z","isPatch":false,"sender":{"key":"prohaska@zib.de","avatar":"https://avatars.githubusercontent.com/u/217580?v=4"},"body":"\nOn Sun, 23 Mar 2008, Johannes Schindelin wrote:\n\n> On Sun, 23 Mar 2008, Steffen Prohaska wrote:\n> \n> > On Sun, 23 Mar 2008, Johannes Schindelin wrote:\n> > \n> > > On Sun, 23 Mar 2008, Steffen Prohaska wrote:\n> > > \n> > > > On Sun, 23 Mar 2008, Johannes Schindelin wrote:\n> > > > \n> > > > > The point is: if we use /etc/gitconfig, we also touch _existing_ \n> > > > > setups (as Junio pointed out).  Which, in the case of autocrlf, is \n> > > > > not desirable.\n> > > > \n> > > > I proposed a mechanism that would avoid such problems in the future.\n> > > \n> > > Yes, but your solution feels a bit limited and \"hot-needled\" for just \n> > > one purpose.\n> > \n> > What limits do you mean (except that it does still break existing \n> > msysgit setups; but would avoid this problem in the future)?\n> \n> I have the impression that a problem just like this will arise again, just \n> not with corelf, but with another setting that the admin might want to \n> set per default in git-init, but the user might want to override.\n\nMy patch does not set the default in git-init, but only stores the\ncurrent choice of autocrlf in the repository's config.  autocrlf is\nspecial because it cannot be easily changed after the initial checkout.\nChanging autocrlf might require converting the line endings of all files\nin the work tree.  This is very different from most other configuration\nvariables, which can be changed without requiring any modifications to\nthe work tree.\n\nIn some sense you cannot change autocrlf at all after a repository is\ninitialized.  At least you need a deep understanding of the autocrlf\nmechanism to avoid unexpected behavior.  Once you checked out files,\nthese files might 'preserve' the setting of autocrlf during the\ncheckout.  For example if you use autocrlf=true during checkout and\nlater change to autocrlf=false, git will detect all files as changed\nbecause they contain CRLF in the workspace but LF in the repository.\n\nThe situation is even worse, because the choice of autocrlf is not\na purely local one, but depends on the project you are cloning.  A sane\npolicy is to have only LF line-endings in the repository and use native\nline-endings in the work tree.  This can be guaranteed with\nautocrlf=input on Unix and autocrlf=true on Windows.  Another possible\nchoice is to tell git to not modify any content at all, which\nautocrlf=false would give you.  Personally, I do not think the latter is\na reasonable choice, but other might have a different opinion.  My point\nis that it is the choice of the project: Either *all* repositories that\nclone the project should set autocrlf=input|true or *all* repositories\nshould set autocrlf=false.  It is neither the choice of the local admin,\nnor the local user, nor the default of git.  You need to have\nproject-specific knowledge to make the right choice.\n\nI suspect that a lot of projects implicitly chose autocrlf=false because\nof lacking autocrlf support in the past.  The default of git was to not\ntouch the content at all; and still this is the default on Unix.  Only\nlately we tried to provide a more sensible default on Windows.\n\nAll projects that implicitly assume autocrlf=false might get into\ntrouble if we change the default, no matter which way we do this.  For\nexample we could use the templates to provide a new default.  The\nexisting repository's settings would not change.  But the next time the\nuser clones such a repository the clone would have the new settings and\nthis would cause trouble if the project contains files with mixed\nline-endings.  The same happens if we directly modify git's default.\nThe only difference is that the trouble surfaces immediately because the\nnew default affects existing repositories.\n\nA possible solution would be if a project (not a single repository)\ncould specify autocrlf and the choice was preserved across cloning.\nI do not advocate this solution.  Such a mechanism is not available and\nI personally do not know why it should be added.  As I pointed out above\nI believe that autocrlf=input|true is the only sane way of handling\ncross-platform projects and if git's binary auto-detection fails to\ndetect a file you should by all means add it to .gitattributes.  This is\nthe only way to guarantee that the file will be properly handled with\nany autocrlf settings.\n\nThe solution I propose is to change the default now; tell the users\nabout the change; explain again and again why it is good to enforce LF\nline-endings in the repository; and fix all repositories that contain\nCRLF line-endings ASAP.\n\nBut even if all repositories contained only LF, the original problem\nwould remain.  The work tree depends on the choice of autocrlf during\ncheckout and cannot be easily modified later.  Not only the admin or the\nmaintainer of git can cause trouble by changing the default.  The user\nhimself can cause trouble by modifying the setup with \"git config\n--global\".\n\nThis is where my proposed patch kicks in.  I propose to modify init-db\nto store the choice of autocrlf in the repository to preserve it for\nthis repository, no matter who made this choice and no matter who\ndecides to change the setup later.  Only if the user deliberately\nchooses to modify the local setting of the repository he might get into\ntrouble; but git always gives you this kind of freedom, no?\n\nYet the patch does not protect you from all trouble.  It only works well\nin all cases if you have a repository that contains only LF.  If this is\nthe case you are free to choose autocrlf=input or autocrlf=true.  Both\nwill give you work trees without unexpected diffs right after checkout;\nand both choices will guarantee that CRLFs will never enter the\nrepository.  Still you must not thoughtlessly change autocrlf without\nfixing the line endings of the checked out files.\n\n            Steffen\n"},{"id":"72829","messageId":"alpine.LSU.1.00.0803240038180.4353@racer.site","threadId":"12813","inReplyTo":"alpine.OSX.1.00.0803232237400.19285@cougar","subject":"Re: [msysGit] Re: Store autocrlf during init-db (was [msysGit] autocrlf problems with Git-preview20080301.exe)","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-23T23:39:27Z","receivedAt":"2008-03-23T23:39:27Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 23 Mar 2008, Steffen Prohaska wrote:\n\n> On Sun, 23 Mar 2008, Johannes Schindelin wrote:\n> \n> > I have the impression that a problem just like this will arise again, \n> > just not with corelf, but with another setting that the admin might \n> > want to set per default in git-init, but the user might want to \n> > override.\n> \n> My patch does not set the default in git-init, but only stores the\n> current choice of autocrlf in the repository's config.  autocrlf is\n> special because it cannot be easily changed after the initial checkout.\n\nBut basically all clean/smudge filters have exactly the same problem!  And \ncore.ignorecase, too!\n\nThere must be a way to do it elegantly, without catering just for \nautocrlf.\n\nCiao,\nDscho\n"},{"id":"72830","messageId":"20080323235610.GB25381@dpotapov.dyndns.org","threadId":"12813","inReplyTo":"alpine.OSX.1.00.0803231428220.13789@cougar","subject":"Re: Store autocrlf during init-db (was [msysGit] autocrlf problems with Git-preview20080301.exe)","fromName":"Dmitry Potapov","fromEmail":"dpotapov@gmail.com","sentAt":"2008-03-23T23:56:10Z","receivedAt":"2008-03-23T23:56:10Z","isPatch":false,"sender":{"key":"dpotapov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6568595?v=4"},"body":"\nOn Sun, Mar 23, 2008 at 02:42:16PM +0100, Steffen Prohaska wrote:\n> \n> We have two conflicting objectives and I do not know how to meet them\n> the same time:\n> \n>  1) Existing setups should not break.\n> \n>  2) Users should have a way to set a global default for autocrlf that\n>     overrides our defaults.\n> \n> If we store the new default in newly created repositories, (1) would be\n> met but (2) is not possible.  If we support ~/.gitconfig for overriding\n> the system-wide default, (2) is trivial but (1) is hard to meet.\n\n\nTo meet both requirements you have to copy autocrlf setting for each new\nrepository during git init or clone and should never use the global\nvalue for any other purpose than this.\n\nThis means that you do NOT really need the system or global default for\nautocrlf in the sense we have it for other configuration variables, but\nyou need a template value for it.\n\nWe already have templates for different hooks, info/exclude, etc. So,\ninstead of placing autocrlf in /etc/gitconfig, you should place this\nvariable to /usr/share/git/templates/config and this file should be\ncopied by git init or git clone as any other file in templates.\n\n\nDmitry\n"},{"id":"72831","messageId":"alpine.LSU.1.00.0803240101220.4353@racer.site","threadId":"12813","inReplyTo":"20080323235610.GB25381@dpotapov.dyndns.org","subject":"Re: [msysGit] Re: Store autocrlf during init-db (was [msysGit] autocrlf problems with Git-preview20080301.exe)","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-24T00:01:54Z","receivedAt":"2008-03-24T00:01:54Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 24 Mar 2008, Dmitry Potapov wrote:\n\n> We already have templates for different hooks, info/exclude, etc. So, \n> instead of placing autocrlf in /etc/gitconfig, you should place this \n> variable to /usr/share/git/templates/config and this file should be \n> copied by git init or git clone as any other file in templates.\n\nI thought we discussed that already?  And the consensus was that this does \nnot allow for per-user overriding.\n\nCiao,\nDscho\n"},{"id":"72832","messageId":"20080324001634.GC25381@dpotapov.dyndns.org","threadId":"12813","inReplyTo":"alpine.OSX.1.00.0803231032180.7541@cougar","subject":"Re: [PATCH] init-db: Store current value of autocrlf","fromName":"Dmitry Potapov","fromEmail":"dpotapov@gmail.com","sentAt":"2008-03-24T00:16:34Z","receivedAt":"2008-03-24T00:16:34Z","isPatch":true,"sender":{"key":"dpotapov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6568595?v=4"},"body":"On Sun, Mar 23, 2008 at 10:34:13AM +0100, Steffen Prohaska wrote:\n> Storing the current value of autocrlf to preserve it for this repository\n> even if the global setup changes is a good idea.  Changing autocrlf\n> later is tricky because the work tree's line endings depend on the\n> settings during checkout.  Therefore, it makes sense to preserve the\n> value of autocrlf that exists during the first checkout.  In this\n> regards autocrlf is different from, for example, author, because author\n> can be easily changed later without requiring any conversion of existing\n> files in the work tree.\n> \n> This commit modifies the initialization of a new repository to store the\n> current value of autocrlf.\n\nNAK\n\nWhile I agree that preserving autocrlf may be a good idea, I don't like\nthat the idea of making an exception for autocrlf and treating the global\nsettings for it differently than for other variables -- as something that\nshould be copied on init. We have templates for that, so autocrlf should\nbe placed into templates/config and then it will be automatically copied\nwhen a new repository is created. I have tested that now, and it works.\n\n\nDmitry\n"},{"id":"72834","messageId":"20080324002302.GD25381@dpotapov.dyndns.org","threadId":"12813","inReplyTo":"alpine.LSU.1.00.0803240101220.4353@racer.site","subject":"Re: [msysGit] Re: Store autocrlf during init-db (was [msysGit] autocrlf problems with Git-preview20080301.exe)","fromName":"Dmitry Potapov","fromEmail":"dpotapov@gmail.com","sentAt":"2008-03-24T00:23:02Z","receivedAt":"2008-03-24T00:23:02Z","isPatch":false,"sender":{"key":"dpotapov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6568595?v=4"},"body":"On Mon, Mar 24, 2008 at 01:01:54AM +0100, Johannes Schindelin wrote:\n> \n> On Mon, 24 Mar 2008, Dmitry Potapov wrote:\n> \n> > We already have templates for different hooks, info/exclude, etc. So, \n> > instead of placing autocrlf in /etc/gitconfig, you should place this \n> > variable to /usr/share/git/templates/config and this file should be \n> > copied by git init or git clone as any other file in templates.\n> \n> I thought we discussed that already?  And the consensus was that this does \n> not allow for per-user overriding.\n\nI am sorry I missed this discussion. In this case, I believe that the\nidea of templates should be extended, so any user may have his/her own\ntemplates in $HOME/.gittemplates. IMHO, it makes much more sense than\nmaking an exception for autocrlf in builtin-init-db.c and breaking\nexisting repositories...\n\n\nDmitry\n"},{"id":"72871","messageId":"alpine.LSU.1.00.0803241155300.4353@racer.site","threadId":"12813","inReplyTo":"20080324002302.GD25381@dpotapov.dyndns.org","subject":"Re: Store autocrlf during init-db (was [msysGit] autocrlf problems with Git-preview20080301.exe)","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-24T10:57:19Z","receivedAt":"2008-03-24T10:57:19Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nHi,\n\nOn Mon, 24 Mar 2008, Dmitry Potapov wrote:\n\n> On Mon, Mar 24, 2008 at 01:01:54AM +0100, Johannes Schindelin wrote:\n> > \n> > On Mon, 24 Mar 2008, Dmitry Potapov wrote:\n> > \n> > > We already have templates for different hooks, info/exclude, etc. \n> > > So, instead of placing autocrlf in /etc/gitconfig, you should place \n> > > this variable to /usr/share/git/templates/config and this file \n> > > should be copied by git init or git clone as any other file in \n> > > templates.\n> > \n> > I thought we discussed that already?  And the consensus was that this \n> > does not allow for per-user overriding.\n> \n> I am sorry I missed this discussion. In this case, I believe that the \n> idea of templates should be extended, so any user may have his/her own \n> templates in $HOME/.gittemplates. IMHO, it makes much more sense than \n> making an exception for autocrlf in builtin-init-db.c and breaking \n> existing repositories...\n\nI think I actually suggested something like that.  But that gets only even \nmore complicated: if you have a template for .git/config in \n$HOME/.gittemplates/, then the global template will be _disregarded_, even \nif the administrator puts something vital in there.\n\nMaybe the best idea would be an \"init\" hook, settable from the config, \nafter all.\n\nCiao,\nDscho\n"},{"id":"72880","messageId":"20080324122153.GF25381@dpotapov.dyndns.org","threadId":"12813","inReplyTo":"alpine.LSU.1.00.0803241155300.4353@racer.site","subject":"Re: Store autocrlf during init-db (was [msysGit] autocrlf problems with Git-preview20080301.exe)","fromName":"Dmitry Potapov","fromEmail":"dpotapov@gmail.com","sentAt":"2008-03-24T12:21:53Z","receivedAt":"2008-03-24T12:21:53Z","isPatch":false,"sender":{"key":"dpotapov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6568595?v=4"},"body":"\nOn Mon, Mar 24, 2008 at 11:57:19AM +0100, Johannes Schindelin wrote:\n> \n> I think I actually suggested something like that.  But that gets only even \n> more complicated: if you have a template for .git/config in \n> $HOME/.gittemplates/, then the global template will be _disregarded_, even \n> if the administrator puts something vital in there.\n\nMaybe, because I cannot imagine what so vital the administrator can put\nin it, I really do not see that as a problem. I believe that any good\nadministrator should notify all users about any vital changes anyway, \nbecause if these changes are vital, it may be necessary not only change\ntemplates in $HOME/.gittemplates/ (which very few users will probably\nhave), but perhaps also in existing repositories...\n\n> \n> Maybe the best idea would be an \"init\" hook, settable from the config, \n> after all.\n\nI agree that seems to be the best solution as it is more flexible than\nhaving $HOME/.gittemplates/.\n\nDmitry\n"},{"id":"72904","messageId":"alpine.LSU.1.00.0803241611200.4353@racer.site","threadId":"12813","inReplyTo":"20080324122153.GF25381@dpotapov.dyndns.org","subject":"[PATCH] Introduce core.initHook","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-24T15:12:53Z","receivedAt":"2008-03-24T15:12:53Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nThis variable, if set, specifies the path of a hook which is executed\nafter every git-init.\n\nIt can be used to override settings in the templates per-user.  For \nexample, when the adminstrator set core.autoCRLF=true in the templates, \nbut you want to avoid that explicitely.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tOn Mon, 24 Mar 2008, Dmitry Potapov wrote:\n\n\t> On Mon, Mar 24, 2008 at 11:57:19AM +0100, Johannes Schindelin \n\t> wrote:\n\t> > \n\t> > Maybe the best idea would be an \"init\" hook, settable from the \n\t> > config, after all.\n\t> \n\t> I agree that seems to be the best solution as it is more \n\t> flexible than having $HOME/.gittemplates/.\n\n Documentation/config.txt   |    4 ++++\n Documentation/git-init.txt |    3 +++\n builtin-init-db.c          |   26 ++++++++++++++++++++++++++\n t/t0001-init.sh            |   21 +++++++++++++++++++++\n 4 files changed, 54 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex efde54d..3323724 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -358,6 +358,10 @@ core.whitespace::\n   does not trigger if the character before such a carriage-return\n   is not a whitespace (not enabled by default).\n \n+core.inithook::\n+\tThe path to a program which is run after each call to\n+\tlinkgit:git-init[1].\n+\n alias.*::\n \tCommand aliases for the linkgit:git[1] command wrapper - e.g.\n \tafter defining \"alias.last = cat-file commit HEAD\", the invocation\ndiff --git a/Documentation/git-init.txt b/Documentation/git-init.txt\nindex 03a4f0e..e082218 100644\n--- a/Documentation/git-init.txt\n+++ b/Documentation/git-init.txt\n@@ -60,6 +60,9 @@ If you are initializing a non-bare repository, the config variable\n `receive.guardCurrentBranch` is set to true.  This avoids problems with\n pushing into the current branch, which does not touch the working tree.\n \n+If you want to run a specific script everytime git-init was issued, you\n+can set the variable `core.initHook`.\n+\n --\n \n \ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex 36c12a2..1975910 100644\n--- a/builtin-init-db.c\n+++ b/builtin-init-db.c\n@@ -6,6 +6,7 @@\n #include \"cache.h\"\n #include \"builtin.h\"\n #include \"exec_cmd.h\"\n+#include \"run-command.h\"\n \n #ifndef DEFAULT_GIT_TEMPLATE_DIR\n #define DEFAULT_GIT_TEMPLATE_DIR \"/usr/share/git-core/templates\"\n@@ -310,6 +311,28 @@ static void guess_repository_type(const char *git_dir)\n \treturn;\n }\n \n+static const char *init_hook;\n+static int config_init_hook(const char *key, const char *value)\n+{\n+\tif (!strcmp(key, \"core.inithook\"))\n+\t\tinit_hook = xstrdup(value);\n+\treturn 0;\n+}\n+\n+static int run_init_hook()\n+{\n+\tconst char *argv[2] = { NULL, NULL };\n+\n+\tgit_config(config_init_hook);\n+\tif (!init_hook)\n+\t\treturn 0;\n+\tif (access(init_hook, X_OK) < 0)\n+\t\treturn error(\"init hook '%s' not found\", init_hook);\n+\n+\targv[0] = init_hook;\n+\treturn run_command_v_opt(argv, 0);\n+}\n+\n static const char init_db_usage[] =\n \"git-init [-q | --quiet] [--template=<template-directory>] [--shared]\";\n \n@@ -407,6 +430,9 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \t\tgit_config_set(\"receive.denyNonFastforwards\", \"true\");\n \t}\n \n+\tif (run_init_hook())\n+\t\treturn 1;\n+\n \tif (!quiet)\n \t\tprintf(\"%s%s Git repository in %s/\\n\",\n \t\t       reinit ? \"Reinitialized existing\" : \"Initialized empty\",\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex c015405..7c18d24 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -113,4 +113,25 @@ test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' '\n \tfi\n '\n \n+cat > init-hook.sh << EOF\n+#!$SHELL_PATH\n+\n+git config test.message success\n+EOF\n+chmod a+x init-hook.sh\n+\n+# using reinit because of lacking system/global config in the tests\n+\n+test_expect_success 'core.initHook' '\n+\n+\tmkdir hook &&\n+\t(cd hook &&\n+\t git init &&\n+\t test -z \"$(git config test.message)\" &&\n+\t git config core.initHook \"$(pwd)\"/../init-hook.sh &&\n+\t git init &&\n+\t test success = \"$(git config test.message)\")\n+\n+'\n+\n test_done\n-- \n1.5.5.rc1.178.gd799d\n"},{"id":"72905","messageId":"alpine.LSU.1.00.0803241613480.4353@racer.site","threadId":"12813","inReplyTo":"alpine.LSU.1.00.0803241611200.4353@racer.site","subject":"[PATCH] init: show \"Reinit\" message even in an (existing) empty repository","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-24T15:14:52Z","receivedAt":"2008-03-24T15:14:52Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nEarlier, git-init tested for a valid HEAD ref, but if the repository\nwas empty, there was none.  Instead, test for the existence of\nthe file $GIT_DIR/HEAD.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tI realised this while testing the core.initHook patch.\n\n builtin-init-db.c |    3 +--\n 1 files changed, 1 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex 1975910..ceb4727 100644\n--- a/builtin-init-db.c\n+++ b/builtin-init-db.c\n@@ -168,10 +168,9 @@ static int create_default_files(const char *git_dir, const char *template_path)\n {\n \tunsigned len = strlen(git_dir);\n \tstatic char path[PATH_MAX];\n-\tunsigned char sha1[20];\n \tstruct stat st1;\n \tchar repo_version_string[10];\n\tint reinit;\n \tint filemode;\n \n \tif (len > sizeof(path)-50)\n@@ -220,7 +219,7 @@ static int create_default_files(const char *git_dir, const char *template_path)\n \t * branch, if it does not exist yet.\n \t */\n \tstrcpy(path + len, \"HEAD\");\n-\treinit = !read_ref(\"HEAD\", sha1);\n+\treinit = !access(path, R_OK);\n \tif (!reinit) {\n \t\tif (create_symref(\"HEAD\", \"refs/heads/master\", NULL) < 0)\n \t\t\texit(1);\n-- \n1.5.5.rc1.178.gd799d\n"},{"id":"72947","messageId":"7vr6dzuaxf.fsf@gitster.siamese.dyndns.org","threadId":"12813","inReplyTo":"alpine.LSU.1.00.0803241611200.4353@racer.site","subject":"Re: [PATCH] Introduce core.initHook","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-24T20:25:16Z","receivedAt":"2008-03-24T20:25:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> diff --git a/Documentation/git-init.txt b/Documentation/git-init.txt\n> index 03a4f0e..e082218 100644\n> --- a/Documentation/git-init.txt\n> +++ b/Documentation/git-init.txt\n> @@ -60,6 +60,9 @@ If you are initializing a non-bare repository, the config variable\n>  `receive.guardCurrentBranch` is set to true.  This avoids problems with\n>  pushing into the current branch, which does not touch the working tree.\n>  \n> +If you want to run a specific script everytime git-init was issued, you\n> +can set the variable `core.initHook`.\n\n... in your $HOME/.gitconfig, naturally ;-)\n\nI like the general idea, but with a few nits.\n\nThe hook might want to differentiate its behaviour based on how git-init\nwas invoked, don't you think?  E.g. was it because the end user wanted to\ncreate a new repo?  Re-init?  Clone, cvsimport or some other higher level\ncommands invoked git-init on the user's behalf?).  The higher level ones\ncould communicate it via environment so we do not have to worry about them\ntoo much (except perhaps in the documentation part to help hook writers),\nbut at least re-init is something init-db alone would be able to tell the\nhook, so either a parameter to the hook or an environment exported to it\nwould be needed.  The hook can figure out 'shared' and 'bare' by reading\nfrom $GIT_DIR/config itself, but are there other things we may want to\ntell the hook?\n\n> +static int config_init_hook(const char *key, const char *value)\n> +{\n> +\tif (!strcmp(key, \"core.inithook\"))\n> +\t\tinit_hook = xstrdup(value);\n> +\treturn 0;\n\nThe current way to spell this is with git_config_string() to protect\nyourself from segfaulting on:\n\n\t[core]\n        \tinithook\n\n\n> @@ -407,6 +430,9 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n>  \t\tgit_config_set(\"receive.denyNonFastforwards\", \"true\");\n>  \t}\n>  \n> +\tif (run_init_hook())\n> +\t\treturn 1;\n> +\n\nHmm.  Exit without a message even under !quiet?\n\n>  \tif (!quiet)\n>  \t\tprintf(\"%s%s Git repository in %s/\\n\",\n>  \t\t       reinit ? \"Reinitialized existing\" : \"Initialized empty\",\n"},{"id":"72956","messageId":"alpine.LSU.1.00.0803242232410.4353@racer.site","threadId":"12813","inReplyTo":"7vr6dzuaxf.fsf@gitster.siamese.dyndns.org","subject":"[PATCH v2] Introduce core.initHook","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-24T21:40:07Z","receivedAt":"2008-03-24T21:40:07Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\n\nThis variable, if set, specifies the path of a hook which is executed\nafter every git-init.  It can be used to override settings in the\ntemplates per-user.\n\nIn case of a re-initialization, the hook gets called with the argument\n\"reinit\".\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tOn Mon, 24 Mar 2008, Junio C Hamano wrote:\n\n\t> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\t> \n\t> > If you want to run a specific script everytime git-init was \n\t> > issued, you can set the variable `core.initHook`.\n\t> \n\t> ... in your $HOME/.gitconfig, naturally ;-)\n\n\tNaturally.\n\n\t> I like the general idea, but with a few nits.\n\t> \n\t> The hook might want to differentiate its behaviour based on how \n\t> git-init was invoked, don't you think?\n\n\tOkay.  It now gets an argument \"reinit\" when reinitialised.  As \n\tyou said, the other usages (clone, cvsimport, ...) are a bit \n\tfiddly to implement.\n\n\t> > +static int config_init_hook(const char *key, const char *value)\n\t> > +{\n\t> > +\tif (!strcmp(key, \"core.inithook\"))\n\t> > +\t\tinit_hook = xstrdup(value);\n\t> > +\treturn 0;\n\t> \n\t> The current way to spell this is with git_config_string() to \n\t> protect yourself from segfaulting on:\n\n\tYeah, sorry.  Fixed.\n\n\t> > @@ -407,6 +430,9 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n\t> >  \t\tgit_config_set(\"receive.denyNonFastforwards\", \"true\");\n\t> >  \t}\n\t> >  \n\t> > +\tif (run_init_hook())\n\t> > +\t\treturn 1;\n\t> > +\n\t> \n\t> Hmm.  Exit without a message even under !quiet?\n\n\tEven under quiet, run_init_hook() will complain if the hook is \n\tinvalid.\n\n\n Documentation/config.txt   |    5 +++++\n Documentation/git-init.txt |    6 ++++++\n builtin-init-db.c          |   28 ++++++++++++++++++++++++++++\n t/t0001-init.sh            |   21 +++++++++++++++++++++\n 4 files changed, 60 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex efde54d..355f049 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -358,6 +358,11 @@ core.whitespace::\n   does not trigger if the character before such a carriage-return\n   is not a whitespace (not enabled by default).\n \n+core.inithook::\n+\tThe path to a program which is run after each call to\n+\tlinkgit:git-init[1].  The hook is called with the argument\n+\t\"reinit\" if an existing repository is re-initialized.\n+\n alias.*::\n \tCommand aliases for the linkgit:git[1] command wrapper - e.g.\n \tafter defining \"alias.last = cat-file commit HEAD\", the invocation\ndiff --git a/Documentation/git-init.txt b/Documentation/git-init.txt\nindex 03a4f0e..26deaaf 100644\n--- a/Documentation/git-init.txt\n+++ b/Documentation/git-init.txt\n@@ -60,6 +60,12 @@ If you are initializing a non-bare repository, the config variable\n `receive.guardCurrentBranch` is set to true.  This avoids problems with\n pushing into the current branch, which does not touch the working tree.\n \n+If you want to run a specific script everytime git-init was issued, you\n+can set the variable `core.initHook` in /etc/gitconfig or $HOME/.gitconfig,\n+or in the existing repository when re-initializing.  In the case that you\n+reinitialize a repository, the hook is called with the single argument\n+\"reinit\".\n+\n --\n \n \ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex 36c12a2..e1a54b5 100644\n--- a/builtin-init-db.c\n+++ b/builtin-init-db.c\n@@ -6,6 +6,7 @@\n #include \"cache.h\"\n #include \"builtin.h\"\n #include \"exec_cmd.h\"\n+#include \"run-command.h\"\n \n #ifndef DEFAULT_GIT_TEMPLATE_DIR\n #define DEFAULT_GIT_TEMPLATE_DIR \"/usr/share/git-core/templates\"\n@@ -310,6 +311,30 @@ static void guess_repository_type(const char *git_dir)\n \treturn;\n }\n \n+static const char *init_hook;\n+static int config_init_hook(const char *key, const char *value)\n+{\n+\tif (!strcmp(key, \"core.inithook\"))\n+\t\treturn git_config_string(&init_hook, key, value);\n+\treturn 0;\n+}\n+\n+static int run_init_hook(int reinit)\n+{\n+\tconst char *argv[3] = { NULL, NULL, NULL };\n+\n+\tgit_config(config_init_hook);\n+\tif (!init_hook)\n+\t\treturn 0;\n+\tif (access(init_hook, X_OK) < 0)\n+\t\treturn error(\"init hook '%s' not found\", init_hook);\n+\n+\targv[0] = init_hook;\n+\tif (reinit)\n+\t\targv[1] = \"reinit\";\n+\treturn run_command_v_opt(argv, 0);\n+}\n+\n static const char init_db_usage[] =\n \"git-init [-q | --quiet] [--template=<template-directory>] [--shared]\";\n \n@@ -407,6 +432,9 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \t\tgit_config_set(\"receive.denyNonFastforwards\", \"true\");\n \t}\n \n+\tif (run_init_hook(reinit))\n+\t\treturn 1;\n+\n \tif (!quiet)\n \t\tprintf(\"%s%s Git repository in %s/\\n\",\n \t\t       reinit ? \"Reinitialized existing\" : \"Initialized empty\",\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex c015405..7c18d24 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -113,4 +113,25 @@ test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' '\n \tfi\n '\n \n+cat > init-hook.sh << EOF\n+#!$SHELL_PATH\n+\n+git config test.message success\n+EOF\n+chmod a+x init-hook.sh\n+\n+# using reinit because of lacking system/global config in the tests\n+\n+test_expect_success 'core.initHook' '\n+\n+\tmkdir hook &&\n+\t(cd hook &&\n+\t git init &&\n+\t test -z \"$(git config test.message)\" &&\n+\t git config core.initHook \"$(pwd)\"/../init-hook.sh &&\n+\t git init &&\n+\t test success = \"$(git config test.message)\")\n+\n+'\n+\n test_done\n-- \n1.5.5.rc1.178.gd799d\n"},{"id":"72966","messageId":"7vhcevu4ou.fsf@gitster.siamese.dyndns.org","threadId":"12813","inReplyTo":"alpine.LSU.1.00.0803242232410.4353@racer.site","subject":"Re: [PATCH v2] Introduce core.initHook","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-24T22:40:01Z","receivedAt":"2008-03-24T22:40:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> \t> > +\tif (run_init_hook())\n> \t> > +\t\treturn 1;\n> \t> > +\n> \t> \n> \t> Hmm.  Exit without a message even under !quiet?\n>\n> \tEven under quiet, run_init_hook() will complain if the hook is \n> \tinvalid.\n\nSorry, I may have been unclear but I was wondering more about the case the\nhook script errored out silently.\n"},{"id":"72976","messageId":"alpine.LSU.1.00.0803250020490.4353@racer.site","threadId":"12813","inReplyTo":"7vhcevu4ou.fsf@gitster.siamese.dyndns.org","subject":"[PATCH v3] Introduce core.initHook","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-24T23:21:59Z","receivedAt":"2008-03-24T23:21:59Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\n\nThis variable, if set, specifies the path of a hook which is executed\nafter every git-init.  It can be used to override settings in the\ntemplates per-user.\n\nIn case of a re-initialization, the hook gets called with the argument\n\"reinit\".\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\nOn Mon, 24 Mar 2008, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > \t> > +\tif (run_init_hook())\n> > \t> > +\t\treturn 1;\n> > \t> > +\n> > \t> \n> > \t> Hmm.  Exit without a message even under !quiet?\n> >\n> > \tEven under quiet, run_init_hook() will complain if the hook is \n> > \tinvalid.\n> \n> Sorry, I may have been unclear but I was wondering more about the case the\n> hook script errored out silently.\n\nOoops.  You're right.  This is the interdiff:\n\ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex e1a54b5..cdeb1d7 100644\n--- a/builtin-init-db.c\n+++ b/builtin-init-db.c\n@@ -332,7 +332,8 @@ static int run_init_hook(int reinit)\n        argv[0] = init_hook;\n        if (reinit)\n                argv[1] = \"reinit\";\n-       return run_command_v_opt(argv, 0);\n+       return run_command_v_opt(argv, 0) ?\n+               error(\"hook '%s' failed\", init_hook) : 0;\n }\n\n\n Documentation/config.txt   |    5 +++++\n Documentation/git-init.txt |    6 ++++++\n builtin-init-db.c          |   29 +++++++++++++++++++++++++++++\n t/t0001-init.sh            |   21 +++++++++++++++++++++\n 4 files changed, 61 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex efde54d..355f049 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -358,6 +358,11 @@ core.whitespace::\n   does not trigger if the character before such a carriage-return\n   is not a whitespace (not enabled by default).\n \n+core.inithook::\n+\tThe path to a program which is run after each call to\n+\tlinkgit:git-init[1].  The hook is called with the argument\n+\t\"reinit\" if an existing repository is re-initialized.\n+\n alias.*::\n \tCommand aliases for the linkgit:git[1] command wrapper - e.g.\n \tafter defining \"alias.last = cat-file commit HEAD\", the invocation\ndiff --git a/Documentation/git-init.txt b/Documentation/git-init.txt\nindex 03a4f0e..26deaaf 100644\n--- a/Documentation/git-init.txt\n+++ b/Documentation/git-init.txt\n@@ -60,6 +60,12 @@ If you are initializing a non-bare repository, the config variable\n `receive.guardCurrentBranch` is set to true.  This avoids problems with\n pushing into the current branch, which does not touch the working tree.\n \n+If you want to run a specific script everytime git-init was issued, you\n+can set the variable `core.initHook` in /etc/gitconfig or $HOME/.gitconfig,\n+or in the existing repository when re-initializing.  In the case that you\n+reinitialize a repository, the hook is called with the single argument\n+\"reinit\".\n+\n --\n \n \ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex 36c12a2..cdeb1d7 100644\n--- a/builtin-init-db.c\n+++ b/builtin-init-db.c\n@@ -6,6 +6,7 @@\n #include \"cache.h\"\n #include \"builtin.h\"\n #include \"exec_cmd.h\"\n+#include \"run-command.h\"\n \n #ifndef DEFAULT_GIT_TEMPLATE_DIR\n #define DEFAULT_GIT_TEMPLATE_DIR \"/usr/share/git-core/templates\"\n@@ -310,6 +311,31 @@ static void guess_repository_type(const char *git_dir)\n \treturn;\n }\n \n+static const char *init_hook;\n+static int config_init_hook(const char *key, const char *value)\n+{\n+\tif (!strcmp(key, \"core.inithook\"))\n+\t\treturn git_config_string(&init_hook, key, value);\n+\treturn 0;\n+}\n+\n+static int run_init_hook(int reinit)\n+{\n+\tconst char *argv[3] = { NULL, NULL, NULL };\n+\n+\tgit_config(config_init_hook);\n+\tif (!init_hook)\n+\t\treturn 0;\n+\tif (access(init_hook, X_OK) < 0)\n+\t\treturn error(\"init hook '%s' not found\", init_hook);\n+\n+\targv[0] = init_hook;\n+\tif (reinit)\n+\t\targv[1] = \"reinit\";\n+\treturn run_command_v_opt(argv, 0) ?\n+\t\terror(\"hook '%s' failed\", init_hook) : 0;\n+}\n+\n static const char init_db_usage[] =\n \"git-init [-q | --quiet] [--template=<template-directory>] [--shared]\";\n \n@@ -407,6 +433,9 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \t\tgit_config_set(\"receive.denyNonFastforwards\", \"true\");\n \t}\n \n+\tif (run_init_hook(reinit))\n+\t\treturn 1;\n+\n \tif (!quiet)\n \t\tprintf(\"%s%s Git repository in %s/\\n\",\n \t\t       reinit ? \"Reinitialized existing\" : \"Initialized empty\",\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex c015405..7c18d24 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -113,4 +113,25 @@ test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' '\n \tfi\n '\n \n+cat > init-hook.sh << EOF\n+#!$SHELL_PATH\n+\n+git config test.message success\n+EOF\n+chmod a+x init-hook.sh\n+\n+# using reinit because of lacking system/global config in the tests\n+\n+test_expect_success 'core.initHook' '\n+\n+\tmkdir hook &&\n+\t(cd hook &&\n+\t git init &&\n+\t test -z \"$(git config test.message)\" &&\n+\t git config core.initHook \"$(pwd)\"/../init-hook.sh &&\n+\t git init &&\n+\t test success = \"$(git config test.message)\")\n+\n+'\n+\n test_done\n-- \n1.5.5.rc1.178.gd799d\n"},{"id":"73012","messageId":"7viqzbmf2h.fsf@gitster.siamese.dyndns.org","threadId":"12813","inReplyTo":"alpine.LSU.1.00.0803241613480.4353@racer.site","subject":"Re: [PATCH] init: show \"Reinit\" message even in an (existing) empty repository","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-25T07:35:18Z","receivedAt":"2008-03-25T07:35:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> diff --git a/builtin-init-db.c b/builtin-init-db.c\n> index 1975910..ceb4727 100644\n> --- a/builtin-init-db.c\n> +++ b/builtin-init-db.c\n> @@ -168,10 +168,9 @@ static int create_default_files(const char *git_dir, const char *template_path)\n>  {\n>  \tunsigned len = strlen(git_dir);\n>  \tstatic char path[PATH_MAX];\n> -\tunsigned char sha1[20];\n>  \tstruct stat st1;\n>  \tchar repo_version_string[10];\n> \tint reinit;\n\nHere I saw a hand-edit, but that is less of a problem...\n\n>  \tint filemode;\n>  \n>  \tif (len > sizeof(path)-50)\n> @@ -220,7 +219,7 @@ static int create_default_files(const char *git_dir, const char *template_path)\n>  \t * branch, if it does not exist yet.\n>  \t */\n>  \tstrcpy(path + len, \"HEAD\");\n> -\treinit = !read_ref(\"HEAD\", sha1);\n> +\treinit = !access(path, R_OK);\n\nIf this is a HEAD (or .git/HEAD) that is a dangling symlink (we do still\nsupport them, don't we?) wouldn't this access fail?\n\n-- >8 --\nFrom: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nDate: Mon, 24 Mar 2008 16:14:52 +0100\nSubject: [PATCH] init: show \"Reinit\" message even in an (existing) empty repository\n\nEarlier, git-init tested for a valid HEAD ref, but if the repository\nwas empty, there was none.  Instead, test for the existence of\nthe file $GIT_DIR/HEAD.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin-init-db.c |    5 +++--\n t/t0001-init.sh   |   17 +++++++++++++++++\n 2 files changed, 20 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex 79eaf8d..2854868 100644\n--- a/builtin-init-db.c\n+++ b/builtin-init-db.c\n@@ -167,9 +167,9 @@ static int create_default_files(const char *git_dir, const char *template_path)\n {\n \tunsigned len = strlen(git_dir);\n \tstatic char path[PATH_MAX];\n-\tunsigned char sha1[20];\n \tstruct stat st1;\n \tchar repo_version_string[10];\n+\tchar junk[2];\n \tint reinit;\n \tint filemode;\n \n@@ -219,7 +219,8 @@ static int create_default_files(const char *git_dir, const char *template_path)\n \t * branch, if it does not exist yet.\n \t */\n \tstrcpy(path + len, \"HEAD\");\n-\treinit = !read_ref(\"HEAD\", sha1);\n+\treinit = (!access(path, R_OK)\n+\t\t  || readlink(path, junk, sizeof(junk)-1) != -1);\n \tif (!reinit) {\n \t\tif (create_symref(\"HEAD\", \"refs/heads/master\", NULL) < 0)\n \t\t\texit(1);\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex c015405..b0289e3 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -113,4 +113,21 @@ test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' '\n \tfi\n '\n \n+test_expect_success 'reinit' '\n+\n+\t(\n+\t\tunset GIT_CONFIG GIT_WORK_TREE GIT_CONFIG\n+\n+\t\tmkdir again &&\n+\t\tcd again &&\n+\t\tgit init >out1 2>err1 &&\n+\t\tgit init >out2 2>err2\n+\t) &&\n+\tgrep \"Initialized empty\" again/out1 &&\n+\tgrep \"Reinitialized existing\" again/out2 &&\n+\t>again/empty &&\n+\ttest_cmp again/empty again/err1 &&\n+\ttest_cmp again/empty again/err2\n+'\n+\n test_done\n-- \n1.5.5.rc1.121.g1594\n"},{"id":"73019","messageId":"alpine.LSU.1.00.0803251052310.10660@wbgn129.biozentrum.uni-wuerzburg.de","threadId":"12813","inReplyTo":"7viqzbmf2h.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] init: show \"Reinit\" message even in an (existing) empty repository","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-25T09:55:19Z","receivedAt":"2008-03-25T09:55:19Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 25 Mar 2008, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > diff --git a/builtin-init-db.c b/builtin-init-db.c\n> > index 1975910..ceb4727 100644\n> > --- a/builtin-init-db.c\n> > +++ b/builtin-init-db.c\n> > @@ -168,10 +168,9 @@ static int create_default_files(const char *git_dir, const char *template_path)\n> >  {\n> >  \tunsigned len = strlen(git_dir);\n> >  \tstatic char path[PATH_MAX];\n> > -\tunsigned char sha1[20];\n> >  \tstruct stat st1;\n> >  \tchar repo_version_string[10];\n> > \tint reinit;\n> \n> Here I saw a hand-edit, but that is less of a problem...\n\nHeh, yes.  I originally set reinit = 0, and thought I was clever by patch \nediting.  But I have less experience with that than necessary, and then, I \nam not as clever as I thought, either... ;-)\n\n> >  \tint filemode;\n> >  \n> >  \tif (len > sizeof(path)-50)\n> > @@ -220,7 +219,7 @@ static int create_default_files(const char *git_dir, const char *template_path)\n> >  \t * branch, if it does not exist yet.\n> >  \t */\n> >  \tstrcpy(path + len, \"HEAD\");\n> > -\treinit = !read_ref(\"HEAD\", sha1);\n> > +\treinit = !access(path, R_OK);\n> \n> If this is a HEAD (or .git/HEAD) that is a dangling symlink (we do still\n> support them, don't we?) wouldn't this access fail?\n\nRight.  I already saw your commit, and while I would have to think hard if \nit is implementing the correct logic (what does access() do with a \ndangling symlink? Is || correct?), I just trust you.\n\nAlthough I have to admit that having the authorship of this commit is \ngiving me more credit than I deserve.\n\nThanks,\nDscho\n"}]}