pre-init config and hook

Added annex.pre-init-command git config and pre-init-annex hook that is run
before git-annex repository initialization.

This can block initialization. Or it can preform pre-initialization
configuration or tweaking.

I left stdio connected while it's running, so it could also be used for
interactive prompting conceivably, although that would want to use /dev/tty
anyway probably in order to not pollute the stdout of a command when
automatic initialization is done.

Sponsored-by: Dartmouth College's OpenNeuro project
This commit is contained in:
Joey Hess 2025-01-13 14:22:49 -04:00
parent 9e95556d69
commit 42d55bc57c
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
9 changed files with 87 additions and 19 deletions

View file

@ -27,7 +27,11 @@ already initialized git-annex repository.
A top-level `.noannex` file will prevent git-annex init from being used
in a repository. This is useful for repositories that have a policy
reason not to use git-annex. The content of the file will be displayed
to the user who tries to run git-annex init.
to the user who tries to run git-annex init.
The annex.pre-init-command git configuration or pre-init-annex hook
is run before initialization and can exit nonzero as well to prevent
initialization, as well as doing other setup.
# EXAMPLES

View file

@ -1176,6 +1176,16 @@ repository, using [[git-annex-config]]. See its man page for a list.)
Alternatively, a hook script can be installed in
`.git/hooks/pre-commit-annex`
* `annex.pre-init-command`
This command is run before the repository is initialized, either by
`git-annex init`, or automatic initialization. It can configure
the repository in any way needed. If it exits nonzero, the repository
initialization will fail.
Alternatively, a hook script can be installed in
`.git/hooks/pre-init-annex`
* `annex.alwayscompact`
By default, git-annex compacts data it records in the git-annex branch.

View file

@ -6,3 +6,5 @@ The idea is stemmed from discussions/problems with using freeze/thaw hooks, and
[[!meta author=yoh]]
[[!tag projects/openneuro]]
> [[done]] --[[Joey]]

View file

@ -0,0 +1,10 @@
[[!comment format=mdwn
username="joey"
subject="""comment 5"""
date="2025-01-13T17:33:02Z"
content="""
Note that the `.noannex` file that prevents init has some overlap with
a pre-init hook that exits nonzero. I guess the .noannex file has the
benefit of working in every clone of a repository without additional
configuration.
"""]]

View file

@ -0,0 +1,10 @@
[[!comment format=mdwn
username="joey"
subject="""comment 6"""
date="2025-01-13T18:17:42Z"
content="""
Implemented .git/hooks/pre-init-annex
(and alternatively git config annex.pre-init-command)
Note that this is also run before automatic initialization.
"""]]