4

Is it possible to hook all ways of creating git repo? So I can run script when repo is cloned, initialized… (are there any other ways, except moving/copying folder?).

My intention is to track all repos, so I don't need to go through all dirs to run some action (mainly git status as I sometimes forget to commit changes and git gc --auto).

tig
  • 4,803

2 Answers2

5

Hooks are (currently) exclusively configured per-repository, so there can be no active hooks before a repository is created.

If you just want to initialize some repository specific settings identically for all new repositories you might be able to use the repository template mechanism.

By using your own template you can

  • install activated hooks (by providing a <template‑dir>/hooks/<hook‑name> file),
  • set configuration variables (by providing a <template‑dir>/config file), and
  • configure per-repository exclude rules or attributes (by providing a <template‑dir>/info/exclude or <template‑dir/info/attributes> file).

Any configuration file that lives in a .git directory can be placed in a template to serve as the initial copy for that file in new repositories initialized from the template. I suppose you could even provide initial objects and refs.

Once you have a template directory made up with your customizations you must tell git init and git clone where to find it. This can be done explicitly with the --template option (Git 0.99.4 or later), or implicitly with the GIT_TEMPLATE_DIR environment variable (Git 1.5.0 or later), or implicitly by setting the init.templatedir configuration variable in the “global” (per-user) or “system” Git configuration files (i.e. ~/.gitconfig or /etc/gitconfig (varies by installation); Git 1.7.1 or later).

Chris Johnsen
  • 42,029
0

You cannot "track" git repos (as in "ask some central referential the list of currently active git repo).
Each git repo is independent from another.

Two solutions might be considered:

  • a git template as in Chris's answer, with one of the client-side hooks able, on the first use, to register the git repo in some "central" file.
    That file would then be read by an external script (external to git), in order to make the relevant git status or git gc that you want.

  • if all your git repos are declared under the same common directory, you could declare a global parent git repo and add all the sub-repos as submodules.
    Since git1.7.0, git status knows when a submodule contains uncommitted changes.

VonC
  • 14,588