* [PATCH/RFC] Add post-init hook
@ 2008-10-07 23:10 Jonathan del Strother
2008-10-08 1:53 ` Jeff King
0 siblings, 1 reply; 7+ messages in thread
From: Jonathan del Strother @ 2008-10-07 23:10 UTC (permalink / raw)
To: git; +Cc: Jonathan del Strother
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).
Signed-off-by: Jonathan del Strother <jon.delStrother@bestbefore.tv>
---
I 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.
It's my first git patch that does much C work (even if it was mostly a cut & paste job) - comments would be welcome.
Documentation/config.txt | 4 ++++
Documentation/git-init.txt | 7 +++++++
builtin-init-db.c | 36 ++++++++++++++++++++++++++++++++++--
3 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index bbe38cc..746d663 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -881,6 +881,10 @@ i18n.logOutputEncoding::
Character encoding the commit messages are converted to when
running 'git-log' and friends.
+init.post-init-file::
+ A path to a script to run on the initialization of any git
+ repository.
+
instaweb.browser::
Specify the program that will be used to browse your working
repository in gitweb. See linkgit:git-instaweb[1].
diff --git a/Documentation/git-init.txt b/Documentation/git-init.txt
index 71749c0..c6ab6c9 100644
--- a/Documentation/git-init.txt
+++ b/Documentation/git-init.txt
@@ -113,6 +113,13 @@ $ git add . <2>
<2> add all existing file to the index
+CONFIGURATION
+-------------
+
+The global configuration variable init.post-init-file can be used to specify
+a script to be run whenever a repository is created.
+
+
Author
------
Written by Linus Torvalds <torvalds@osdl.org>
diff --git a/builtin-init-db.c b/builtin-init-db.c
index 8140c12..7a3d5c7 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -6,6 +6,7 @@
#include "cache.h"
#include "builtin.h"
#include "exec_cmd.h"
+#include "run-command.h"
#ifndef DEFAULT_GIT_TEMPLATE_DIR
#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
@@ -17,6 +18,37 @@
#define TEST_FILEMODE 1
#endif
+static const char* post_init_path;
+
+static int init_config(const char *var, const char *value, void *cb)
+{
+ if (!strcasecmp(var, "init.post-init-file")) {
+ return git_config_string(&post_init_path, var, value);
+ }
+ return git_default_config(var, value, cb);
+}
+
+
+static int post_init_hook()
+{
+ if (!post_init_path)
+ return 0;
+
+ struct child_process proc;
+ const char *argv[2];
+
+ if (access(post_init_path, X_OK) < 0)
+ return 0;
+
+ memset(&proc, 0, sizeof(proc));
+ argv[0] = post_init_path;
+ argv[1] = NULL;
+ proc.argv = argv;
+ proc.no_stdin = 1;
+ proc.stdout_to_stderr = 1;
+ return run_command(&proc);
+}
+
static void safe_create_dir(const char *dir, int share)
{
if (mkdir(dir, 0777) < 0) {
@@ -190,7 +222,7 @@ static int create_default_files(const char *template_path)
*/
copy_templates(template_path);
- git_config(git_default_config, NULL);
+ git_config(init_config, NULL);
/*
* We would have created the above under user's umask -- under
@@ -321,7 +353,7 @@ int init_db(const char *template_dir, unsigned int flags)
shared_repository ? " shared" : "",
get_git_dir());
- return 0;
+ return post_init_hook();
}
static int guess_repository_type(const char *git_dir)
--
1.6.0.2.454.g27632.dirty
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH/RFC] Add post-init hook
2008-10-07 23:10 [PATCH/RFC] Add post-init hook Jonathan del Strother
@ 2008-10-08 1:53 ` Jeff King
2008-10-08 8:16 ` Jonathan del Strother
0 siblings, 1 reply; 7+ messages in thread
From: Jeff King @ 2008-10-08 1:53 UTC (permalink / raw)
To: Jonathan del Strother; +Cc: git
On Wed, Oct 08, 2008 at 12:10:33AM +0100, Jonathan del Strother wrote:
> I 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.
Why is the --template parameter to clone and init not sufficient?
-Peff
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH/RFC] Add post-init hook
2008-10-08 1:53 ` Jeff King
@ 2008-10-08 8:16 ` Jonathan del Strother
2008-10-09 1:41 ` Jeff King
0 siblings, 1 reply; 7+ messages in thread
From: Jonathan del Strother @ 2008-10-08 8:16 UTC (permalink / raw)
To: Jeff King; +Cc: git
On Wed, Oct 8, 2008 at 2:53 AM, Jeff King <peff@peff.net> wrote:
> On Wed, Oct 08, 2008 at 12:10:33AM +0100, Jonathan del Strother wrote:
>
>> I 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.
>
> Why is the --template parameter to clone and init not sufficient?
>
Partly that I never remember to include the --template parameter,
partly that I wanted to customize its behaviour (it copies the files,
I want symlinks so I only have to edit my hooks in one place whenever
I change them)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH/RFC] Add post-init hook
2008-10-08 8:16 ` Jonathan del Strother
@ 2008-10-09 1:41 ` Jeff King
2008-10-09 11:24 ` Junio C Hamano
0 siblings, 1 reply; 7+ messages in thread
From: Jeff King @ 2008-10-09 1:41 UTC (permalink / raw)
To: Jonathan del Strother; +Cc: git
On Wed, Oct 08, 2008 at 09:16:56AM +0100, Jonathan del Strother wrote:
> > Why is the --template parameter to clone and init not sufficient?
> >
> Partly that I never remember to include the --template parameter,
In that case, I would think a core.template parameter might make more
sense.
> partly that I wanted to customize its behaviour (it copies the files,
> I want symlinks so I only have to edit my hooks in one place whenever
> I change them)
This makes a lot of sense to me as a best-practice. I wonder if we
wouldn't do better to add a core.symlink-templates option?
-Peff
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH/RFC] Add post-init hook
2008-10-09 1:41 ` Jeff King
@ 2008-10-09 11:24 ` Junio C Hamano
2008-10-09 11:32 ` Jeff King
2008-10-09 11:34 ` Alex Riesen
0 siblings, 2 replies; 7+ messages in thread
From: Junio C Hamano @ 2008-10-09 11:24 UTC (permalink / raw)
To: Jeff King; +Cc: Jonathan del Strother, git
Jeff King <peff@peff.net> writes:
> On Wed, Oct 08, 2008 at 09:16:56AM +0100, Jonathan del Strother wrote:
> ...
>> I want symlinks so I only have to edit my hooks in one place whenever
>> I change them)
>
> This makes a lot of sense to me as a best-practice. I wonder if we
> wouldn't do better to add a core.symlink-templates option?
AFAIR, "git init" copies symlinks in templates as symlinks, so I do not
see why you would even want to have such an option.
Wouldn't it be better if users and installations with such a special
set of templates specified by core.template or --template prepare a
template directory with files and symbolic links of their liking? If
they want some hooks to point at the latest copy of installation specific
standard hook script, templates/hooks/$that_hook can be a symlink to the
real location, no?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH/RFC] Add post-init hook
2008-10-09 11:24 ` Junio C Hamano
@ 2008-10-09 11:32 ` Jeff King
2008-10-09 11:34 ` Alex Riesen
1 sibling, 0 replies; 7+ messages in thread
From: Jeff King @ 2008-10-09 11:32 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Jonathan del Strother, git
On Thu, Oct 09, 2008 at 04:24:29AM -0700, Junio C Hamano wrote:
> > This makes a lot of sense to me as a best-practice. I wonder if we
> > wouldn't do better to add a core.symlink-templates option?
>
> AFAIR, "git init" copies symlinks in templates as symlinks, so I do not
> see why you would even want to have such an option.
Ah, I didn't realize that. In that case, yes, setting up a template
directory of symlinks makes the most sense. I think a core.template
option is still worthwhile, though.
-Peff
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH/RFC] Add post-init hook
2008-10-09 11:24 ` Junio C Hamano
2008-10-09 11:32 ` Jeff King
@ 2008-10-09 11:34 ` Alex Riesen
1 sibling, 0 replies; 7+ messages in thread
From: Alex Riesen @ 2008-10-09 11:34 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Jeff King, Jonathan del Strother, git
2008/10/9 Junio C Hamano <gitster@pobox.com>:
> Jeff King <peff@peff.net> writes:
>> On Wed, Oct 08, 2008 at 09:16:56AM +0100, Jonathan del Strother wrote:
>> ...
>>> I want symlinks so I only have to edit my hooks in one place whenever
>>> I change them)
>>
>> This makes a lot of sense to me as a best-practice. I wonder if we
>> wouldn't do better to add a core.symlink-templates option?
>
> AFAIR, "git init" copies symlinks in templates as symlinks, so I do not
> see why you would even want to have such an option.
>
> Wouldn't it be better if users and installations with such a special
> set of templates specified by core.template or --template prepare a
> template directory with files and symbolic links of their liking? If
> they want some hooks to point at the latest copy of installation specific
> standard hook script, templates/hooks/$that_hook can be a symlink to the
> real location, no?
It will be replaced with a file next time you update your git installation.
Seems like we need ~/.gitconfig/*...
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-10-09 11:35 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-07 23:10 [PATCH/RFC] Add post-init hook Jonathan del Strother
2008-10-08 1:53 ` Jeff King
2008-10-08 8:16 ` Jonathan del Strother
2008-10-09 1:41 ` Jeff King
2008-10-09 11:24 ` Junio C Hamano
2008-10-09 11:32 ` Jeff King
2008-10-09 11:34 ` Alex Riesen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).