git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Introduce core.initHook

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 24, 2008, 20:25 UTC
Message-ID
<7vr6dzuaxf.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<alpine.LSU.1.00.0803241611200.4353@racer.site>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 10 quoted lines
> diff --git a/Documentation/git-init.txt b/Documentation/git-init.txt
> index 03a4f0e..e082218 100644
> --- a/Documentation/git-init.txt
> +++ b/Documentation/git-init.txt
> @@ -60,6 +60,9 @@ If you are initializing a non-bare repository, the config variable
>  `receive.guardCurrentBranch` is set to true.  This avoids problems with
>  pushing into the current branch, which does not touch the working tree.
>  
> +If you want to run a specific script everytime git-init was issued, you
> +can set the variable `core.initHook`.
... in your $HOME/.gitconfig, naturally ;-)
I like the general idea, but with a few nits.

The hook might want to differentiate its behaviour based on how git-init was invoked, don't you think? E.g. was it because the end user wanted to create a new repo? Re-init? Clone, cvsimport or some other higher level commands invoked git-init on the user's behalf?). The higher level ones could communicate it via environment so we do not have to worry about them too much (except perhaps in the documentation part to help hook writers), but at least re-init is something init-db alone would be able to tell the hook, so either a parameter to the hook or an environment exported to it would be needed. The hook can figure out 'shared' and 'bare' by reading from $GIT_DIR/config itself, but are there other things we may want to tell the hook?

Show 5 quoted lines
> +static int config_init_hook(const char *key, const char *value)
> +{
> +	if (!strcmp(key, "core.inithook"))
> +		init_hook = xstrdup(value);
> +	return 0;

The current way to spell this is with git_config_string() to protect yourself from segfaulting on:

	[core]
        	inithook
Show 7 quoted lines
> @@ -407,6 +430,9 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
>  		git_config_set("receive.denyNonFastforwards", "true");
>  	}
>  
> +	if (run_init_hook())
> +		return 1;
> +
Hmm.  Exit without a message even under !quiet?
>  	if (!quiet)
>  		printf("%s%s Git repository in %s/\n",
>  		       reinit ? "Reinitialized existing" : "Initialized empty",
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 22 of 25 in “Store autocrlf during init-db (was [msysGit] autocrlf problems with Git-preview20080301.exe)”
  1. Steffen ProhaskaMar 23, 2008
  2. init-db: Store current value of autocrlfSteffen Prohaska, Mar 23, 2008
  3. Dmitry PotapovMar 24, 2008
  4. Johannes SchindelinMar 23, 2008
  5. Steffen ProhaskaMar 23, 2008
  6. Johannes SchindelinMar 23, 2008
  7. Steffen ProhaskaMar 23, 2008
  8. Johannes SchindelinMar 23, 2008
  9. Steffen ProhaskaMar 23, 2008
  10. Johannes SchindelinMar 23, 2008
  11. Steffen ProhaskaMar 23, 2008
  12. Johannes SchindelinMar 23, 2008
  13. Dmitry PotapovMar 23, 2008
  14. Johannes SchindelinMar 24, 2008
  15. Dmitry PotapovMar 24, 2008
  16. Johannes SchindelinMar 24, 2008
  17. Dmitry PotapovMar 24, 2008
  18. Introduce core.initHookJohannes Schindelin, Mar 24, 2008
  19. init: show "Reinit" message even in an (existing) empty repositoryJohannes Schindelin, Mar 24, 2008
  20. Junio C HamanoMar 25, 2008
  21. Johannes SchindelinMar 25, 2008
  22. Junio C HamanoMar 24, 2008
  23. Introduce core.initHookJohannes Schindelin, Mar 24, 2008
  24. Junio C HamanoMar 24, 2008
  25. Introduce core.initHookJohannes Schindelin, Mar 24, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.