Skip to content

Commit

Permalink
Fix: Run all repo shared hooks (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabyx authored Nov 10, 2021
1 parent 9611600 commit 89ee69d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion githooks/apps/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ func getRepoSharedHooks(
shRepo := &shared[i]

if checkSharedHook(settings, shRepo, allAddedHooks, hooks.SharedHookTypeV.Repo) {
hs = getHooksInShared(settings, uiSettings, shRepo, ignores, checksums)
hs = append(hs, getHooksInShared(settings, uiSettings, shRepo, ignores, checksums)...)
*allAddedHooks = append(*allAddedHooks, shRepo.RepositoryDir)
}
}
Expand Down
17 changes: 16 additions & 1 deletion tests/step-016.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,23 @@ mkdir -p "$GH_TEST_TMP/shared/hooks-016-b.git/.githooks/pre-commit" &&
git commit -m 'Initial commit' ||
exit 1

mkdir -p "$GH_TEST_TMP/shared/hooks-016-c.git/.githooks/pre-commit" &&
echo "echo 'From shared hook C' >> '$GH_TEST_TMP/test-016.out'" \
>"$GH_TEST_TMP/shared/hooks-016-c.git/.githooks/pre-commit/say-hello" &&
cd "$GH_TEST_TMP/shared/hooks-016-c.git" &&
git init &&
git add . &&
git commit -m 'Initial commit' ||
exit 1

mkdir -p "$GH_TEST_TMP/test16" &&
cd "$GH_TEST_TMP/test16" &&
git init || exit 1

mkdir -p .githooks &&
git config --global githooks.shared "$GH_TEST_TMP/shared/hooks-016-a.git" &&
echo "urls: - file://$GH_TEST_TMP/shared/hooks-016-b.git" >.githooks/.shared.yaml &&
echo -e "urls:\n - file://$GH_TEST_TMP/shared/hooks-016-b.git" \
"\n - file://$GH_TEST_TMP/shared/hooks-016-c.git" >.githooks/.shared.yaml &&
"$GH_TEST_BIN/runner" "$(pwd)"/.git/hooks/post-merge unused ||
exit 1

Expand All @@ -51,6 +61,11 @@ if ! grep -q 'From shared hook B' "$GH_TEST_TMP/test-016.out"; then
exit 1
fi

if ! grep -q 'From shared hook C' "$GH_TEST_TMP/test-016.out"; then
echo "! The third shared hook was not run"
exit 1
fi

# Trigger the shared hooks update
OUT=$("$GH_TEST_BIN/runner" "$(pwd)"/.git/hooks/post-merge unused 2>&1)
if ! echo "$OUT" | grep -q "Updating shared hooks from"; then
Expand Down

0 comments on commit 89ee69d

Please sign in to comment.