Skip to content

Commit 25abbb4

Browse files
committed
test_hook: add a --git-dir option
The `test_hook` helper installs hook scripts into a repository. It currently only supports `-C <dir>` to locate the target, which triggers implicit bare repository discovery and would fail under `safe.bareRepository=explicit`. Add a `--git-dir <dir>` option so that the helper can locate bare repositories explicitly. When given, the internal `git rev-parse --absolute-git-dir` call that resolves the hooks directory uses `--git-dir=<dir>` instead of `-C <dir>`. See 8d1a744 (setup.c: create `safe.bareRepository`, 2022-07-14) for the background on implicit bare repository discovery and why it may become the default to reject it. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent f5ec623 commit 25abbb4

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

t/test-lib-functions.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,8 @@ write_script () {
634634
#
635635
# -C <dir>:
636636
# Run all git commands in directory <dir>
637+
# --git-dir <dir>:
638+
# Use <dir> as the git directory (for bare repositories)
637639
# --setup
638640
# Setup a hook for subsequent tests, i.e. don't remove it in a
639641
# "test_when_finished"
@@ -651,13 +653,18 @@ test_hook () {
651653
disable= &&
652654
remove= &&
653655
indir= &&
656+
gitdir= &&
654657
while test $# != 0
655658
do
656659
case "$1" in
657660
-C)
658661
indir="$2" &&
659662
shift
660663
;;
664+
--git-dir)
665+
gitdir="$2" &&
666+
shift
667+
;;
661668
--setup)
662669
setup=t
663670
;;
@@ -680,7 +687,8 @@ test_hook () {
680687
shift
681688
done &&
682689

683-
git_dir=$(git -C "$indir" rev-parse --absolute-git-dir) &&
690+
git_dir=$(git ${indir:+-C "$indir"} ${gitdir:+--git-dir="$gitdir"} \
691+
rev-parse --absolute-git-dir) &&
684692
hook_dir="$git_dir/hooks" &&
685693
hook_file="$hook_dir/$1" &&
686694
if test -n "$disable$remove"

0 commit comments

Comments
 (0)