{"thread":{"id":"15819","subject":"[PATCH/RFC] Add post-init hook","startedAt":"2008-10-07T23:10:33Z","lastAt":"2008-10-09T11:34:27Z","messageCount":7,"participants":["Jonathan del Strother","Jeff King","Junio C Hamano","Alex Riesen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"92574","messageId":"1223421033-22340-1-git-send-email-jon.delStrother@bestbefore.tv","threadId":"15819","inReplyTo":null,"subject":"[PATCH/RFC] Add post-init hook","fromName":"Jonathan del Strother","fromEmail":"jon.delstrother@bestbefore.tv","sentAt":"2008-10-07T23:10:33Z","receivedAt":"2008-10-07T23:10:33Z","isPatch":true,"sender":{"key":"jon.delstrother@bestbefore.tv","avatar":"https://gravatar.com/avatar/754e21ab701c00e2d21fc261187254c34b2a1c0b959d9ee5be1a295990be3081?d=mp&s=160"},"body":"This adds a configuration variable 'init.post-init-file', to supply a path to a script that will be run following git-init (and thus also git-clone).\n\nSigned-off-by: Jonathan del Strother <jon.delStrother@bestbefore.tv>\n---\n\nI have a number of hooks that I have to install every time I create/clone a repository.  This patch adds a post-init hook that's perfect for setting up that sort of stuff.\nIt's my first git patch that does much C work (even if it was mostly a cut & paste job) - comments would be welcome.\n\n Documentation/config.txt   |    4 ++++\n Documentation/git-init.txt |    7 +++++++\n builtin-init-db.c          |   36 ++++++++++++++++++++++++++++++++++--\n 3 files changed, 45 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex bbe38cc..746d663 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -881,6 +881,10 @@ i18n.logOutputEncoding::\n \tCharacter encoding the commit messages are converted to when\n \trunning 'git-log' and friends.\n \n+init.post-init-file::\n+\tA path to a script to run on the initialization of any git\n+\trepository.\n+\n instaweb.browser::\n \tSpecify the program that will be used to browse your working\n \trepository in gitweb. See linkgit:git-instaweb[1].\ndiff --git a/Documentation/git-init.txt b/Documentation/git-init.txt\nindex 71749c0..c6ab6c9 100644\n--- a/Documentation/git-init.txt\n+++ b/Documentation/git-init.txt\n@@ -113,6 +113,13 @@ $ git add .     <2>\n <2> add all existing file to the index\n \n \n+CONFIGURATION\n+-------------\n+\n+The global configuration variable init.post-init-file can be used to specify\n+a script to be run whenever a repository is created.\n+\n+\n Author\n ------\n Written by Linus Torvalds <torvalds@osdl.org>\ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex 8140c12..7a3d5c7 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@@ -17,6 +18,37 @@\n #define TEST_FILEMODE 1\n #endif\n \n+static const char* post_init_path;\n+\n+static int init_config(const char *var, const char *value, void *cb)\n+{\n+\tif (!strcasecmp(var, \"init.post-init-file\")) {\n+\t\treturn git_config_string(&post_init_path, var, value);\n+\t}\n+\treturn git_default_config(var, value, cb);\n+}\n+\n+\n+static int post_init_hook()\n+{\n+\tif (!post_init_path)\n+\t\treturn 0;\n+\n+\tstruct child_process proc;\n+\tconst char *argv[2];\n+\n+\tif (access(post_init_path, X_OK) < 0)\n+\t\treturn 0;\n+\n+\tmemset(&proc, 0, sizeof(proc));\n+\targv[0] = post_init_path;\n+\targv[1] = NULL;\n+\tproc.argv = argv;\n+\tproc.no_stdin = 1;\n+\tproc.stdout_to_stderr = 1;\n+\treturn run_command(&proc);\n+}\n+\n static void safe_create_dir(const char *dir, int share)\n {\n \tif (mkdir(dir, 0777) < 0) {\n@@ -190,7 +222,7 @@ static int create_default_files(const char *template_path)\n \t */\n \tcopy_templates(template_path);\n \n-\tgit_config(git_default_config, NULL);\n+\tgit_config(init_config, NULL);\n \n \t/*\n \t * We would have created the above under user's umask -- under\n@@ -321,7 +353,7 @@ int init_db(const char *template_dir, unsigned int flags)\n \t\t       shared_repository ? \" shared\" : \"\",\n \t\t       get_git_dir());\n \n-\treturn 0;\n+\treturn post_init_hook();\n }\n \n static int guess_repository_type(const char *git_dir)\n-- \n1.6.0.2.454.g27632.dirty\n"},{"id":"92575","messageId":"20081008015352.GA29313@coredump.intra.peff.net","threadId":"15819","inReplyTo":"1223421033-22340-1-git-send-email-jon.delStrother@bestbefore.tv","subject":"Re: [PATCH/RFC] Add post-init hook","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-10-08T01:53:52Z","receivedAt":"2008-10-08T01:53:52Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Oct 08, 2008 at 12:10:33AM +0100, Jonathan del Strother wrote:\n\n> I have a number of hooks that I have to install every time I\n> create/clone a repository.  This patch adds a post-init hook that's\n> perfect for setting up that sort of stuff.\n\nWhy is the --template parameter to clone and init not sufficient?\n\n-Peff\n"},{"id":"92605","messageId":"57518fd10810080116gd876f9bv169f575087baccd7@mail.gmail.com","threadId":"15819","inReplyTo":"20081008015352.GA29313@coredump.intra.peff.net","subject":"Re: [PATCH/RFC] Add post-init hook","fromName":"Jonathan del Strother","fromEmail":"jon.delstrother@bestbefore.tv","sentAt":"2008-10-08T08:16:56Z","receivedAt":"2008-10-08T08:16:56Z","isPatch":true,"sender":{"key":"jon.delstrother@bestbefore.tv","avatar":"https://gravatar.com/avatar/754e21ab701c00e2d21fc261187254c34b2a1c0b959d9ee5be1a295990be3081?d=mp&s=160"},"body":"On Wed, Oct 8, 2008 at 2:53 AM, Jeff King <peff@peff.net> wrote:\n> On Wed, Oct 08, 2008 at 12:10:33AM +0100, Jonathan del Strother wrote:\n>\n>> I have a number of hooks that I have to install every time I\n>> create/clone a repository.  This patch adds a post-init hook that's\n>> perfect for setting up that sort of stuff.\n>\n> Why is the --template parameter to clone and init not sufficient?\n>\n Partly that I never remember to include the --template parameter,\npartly that I wanted to customize its behaviour (it copies the files,\nI want symlinks so I only have to edit my hooks in one place whenever\nI change them)\n"},{"id":"92638","messageId":"20081009014146.GA14204@coredump.intra.peff.net","threadId":"15819","inReplyTo":"57518fd10810080116gd876f9bv169f575087baccd7@mail.gmail.com","subject":"Re: [PATCH/RFC] Add post-init hook","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-10-09T01:41:46Z","receivedAt":"2008-10-09T01:41:46Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Oct 08, 2008 at 09:16:56AM +0100, Jonathan del Strother wrote:\n\n> > Why is the --template parameter to clone and init not sufficient?\n> >\n>  Partly that I never remember to include the --template parameter,\n\nIn that case, I would think a core.template parameter might make more\nsense.\n\n> partly that I wanted to customize its behaviour (it copies the files,\n> I want symlinks so I only have to edit my hooks in one place whenever\n> I change them)\n\nThis makes a lot of sense to me as a best-practice. I wonder if we\nwouldn't do better to add a core.symlink-templates option?\n\n-Peff\n"},{"id":"92662","messageId":"7viqs2ovte.fsf@gitster.siamese.dyndns.org","threadId":"15819","inReplyTo":"20081009014146.GA14204@coredump.intra.peff.net","subject":"Re: [PATCH/RFC] Add post-init hook","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-10-09T11:24:29Z","receivedAt":"2008-10-09T11:24:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Wed, Oct 08, 2008 at 09:16:56AM +0100, Jonathan del Strother wrote:\n> ...\n>> I want symlinks so I only have to edit my hooks in one place whenever\n>> I change them)\n>\n> This makes a lot of sense to me as a best-practice. I wonder if we\n> wouldn't do better to add a core.symlink-templates option?\n\nAFAIR, \"git init\" copies symlinks in templates as symlinks, so I do not\nsee why you would even want to have such an option.\n\nWouldn't it be better if users and installations with such a special\nset of templates specified by core.template or --template prepare a\ntemplate directory with files and symbolic links of their liking?  If\nthey want some hooks to point at the latest copy of installation specific\nstandard hook script, templates/hooks/$that_hook can be a symlink to the\nreal location, no?\n"},{"id":"92663","messageId":"20081009113228.GA17523@sigill.intra.peff.net","threadId":"15819","inReplyTo":"7viqs2ovte.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH/RFC] Add post-init hook","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-10-09T11:32:28Z","receivedAt":"2008-10-09T11:32:28Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Oct 09, 2008 at 04:24:29AM -0700, Junio C Hamano wrote:\n\n> > This makes a lot of sense to me as a best-practice. I wonder if we\n> > wouldn't do better to add a core.symlink-templates option?\n> \n> AFAIR, \"git init\" copies symlinks in templates as symlinks, so I do not\n> see why you would even want to have such an option.\n\nAh, I didn't realize that. In that case, yes, setting up a template\ndirectory of symlinks makes the most sense. I think a core.template\noption is still worthwhile, though.\n\n-Peff\n"},{"id":"92664","messageId":"81b0412b0810090434x41d11f18s4fd7a15d812b3ba3@mail.gmail.com","threadId":"15819","inReplyTo":"7viqs2ovte.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH/RFC] Add post-init hook","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2008-10-09T11:34:27Z","receivedAt":"2008-10-09T11:34:27Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"2008/10/9 Junio C Hamano <gitster@pobox.com>:\n> Jeff King <peff@peff.net> writes:\n>> On Wed, Oct 08, 2008 at 09:16:56AM +0100, Jonathan del Strother wrote:\n>> ...\n>>> I want symlinks so I only have to edit my hooks in one place whenever\n>>> I change them)\n>>\n>> This makes a lot of sense to me as a best-practice. I wonder if we\n>> wouldn't do better to add a core.symlink-templates option?\n>\n> AFAIR, \"git init\" copies symlinks in templates as symlinks, so I do not\n> see why you would even want to have such an option.\n>\n> Wouldn't it be better if users and installations with such a special\n> set of templates specified by core.template or --template prepare a\n> template directory with files and symbolic links of their liking?  If\n> they want some hooks to point at the latest copy of installation specific\n> standard hook script, templates/hooks/$that_hook can be a symlink to the\n> real location, no?\n\nIt will be replaced with a file next time you update your git installation.\nSeems like we need ~/.gitconfig/*...\n"}]}