online.git: scripts/refresh-git-hooks

0 views
Skip to first unread message

"Michael Stahl (via cogerrit)"

unread,
Apr 27, 2026, 2:29:12 AM (2 days ago) Apr 27
to collaboraon...@googlegroups.com
scripts/refresh-git-hooks | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

New commits:
commit 0ff69a26c934e7d58da27adeba9a0383386e0b72
Author: Michael Stahl <michae...@collabora.com>
AuthorDate: Fri Apr 24 17:00:00 2026 +0200
Commit: Miklos Vajna <vmi...@collabora.com>
CommitDate: Mon Apr 27 06:28:58 2026 +0000

refresh-git-hooks: try to make it work in git-worktree

Signed-off-by: Michael Stahl <michae...@collabora.com>
Change-Id: I1e28e0b780032fe984a2b8011263a8c53e3a8563
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/1598
Tested-by: Jenkins CPCI <rel...@collaboraoffice.com>
Reviewed-by: Miklos Vajna <vmi...@collabora.com>
Reviewed-by: Mike Kaganski <mike.k...@collabora.com>

diff --git a/scripts/refresh-git-hooks b/scripts/refresh-git-hooks
index 56e7234e3603..639624d5792d 100755
--- a/scripts/refresh-git-hooks
+++ b/scripts/refresh-git-hooks
@@ -8,14 +8,19 @@ if [ -n "${abs_srcdir}" ]; then
fi

if [ ! -d "${srcdir}/.git" ]; then
- exit 0
+ gitdir=$(git rev-parse --git-common-dir)
+ if [ ! -d "${gitdir}" ]; then
+ exit 0
+ fi
+else
+ gitdir="${srcdir}/.git"
fi

-mkdir -p ${srcdir}/.git/hooks
+mkdir -p "${gitdir}"/hooks

for hook_name in ${srcdir}/.git-hooks/*
do
- hook="${srcdir}/.git/hooks/${hook_name##*/}"
+ hook="${gitdir}/hooks/${hook_name##*/}"
if [ ! -e "${hook}" ]; then
rm -f "${hook}"
ln -sf "${hook_name}" "${hook}"

"Andras Timar (via cogerrit)"

unread,
Apr 28, 2026, 5:53:05 AM (yesterday) Apr 28
to collaboraon...@googlegroups.com
scripts/refresh-git-hooks | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)

New commits:
commit 9a04c32bddd7bffbf0d6be5eed8ead0dae41f849
Author: Andras Timar <andras...@collabora.com>
AuthorDate: Tue Apr 28 11:51:57 2026 +0200
Commit: Andras Timar <andras...@collabora.com>
CommitDate: Tue Apr 28 11:51:57 2026 +0200

refresh-git-hooks: don't abort the build when there is no .git

Building from a release tarball (e.g. RPM packaging) extracts the
sources without a .git directory. The script's `if [ ! -d "${gitdir}" ];
then exit 0; fi` guard is meant to handle exactly that case, but with
`set -e` in effect, `git -C ${srcdir} rev-parse --git-common-dir` fails
first with status 128 ("fatal: not a git repository") and the script
aborts before the guard runs — failing make's all-local target and the
whole RPM build.

Restructure into an if/elif/else so the git invocation's failure
becomes a falsy condition instead of an aborted script, redirect its
stderr so the "fatal:" message no longer pollutes the build log, and
fall through to a clean `exit 0` when there is no git checkout.

Also quote ${srcdir} (paths with spaces) and use `shopt -s nullglob` so
the hook loop is skipped cleanly if .git-hooks/ is empty rather than
trying to symlink the literal glob pattern.

Signed-off-by: Andras Timar <andras...@collabora.com>
Change-Id: I2cb34ae86cdab7949c79e6f28ec4af97c4213696

diff --git a/scripts/refresh-git-hooks b/scripts/refresh-git-hooks
index 19e553e4a20f..c8bfb48dddb0 100755
--- a/scripts/refresh-git-hooks
+++ b/scripts/refresh-git-hooks
@@ -2,23 +2,21 @@

set -e

-srcdir="$PWD"
-if [ -n "${abs_srcdir}" ]; then
- srcdir="${abs_srcdir}"
-fi
+srcdir="${abs_srcdir:-$PWD}"

-if [ ! -d "${srcdir}/.git" ]; then
- gitdir=$(git -C ${srcdir} rev-parse --git-common-dir)
- if [ ! -d "${gitdir}" ]; then
- exit 0
- fi
-else
+if [ -d "${srcdir}/.git" ]; then
gitdir="${srcdir}/.git"
+elif gitdir=$(git -C "${srcdir}" rev-parse --git-common-dir 2>/dev/null) && [ -d "${gitdir}" ]; then
+ :
+else
+ # Not a git checkout (e.g. tarball build) — nothing to do.
+ exit 0
fi

mkdir -p "${gitdir}"/hooks

-for hook_name in ${srcdir}/.git-hooks/*
+shopt -s nullglob
+for hook_name in "${srcdir}"/.git-hooks/*
do
Reply all
Reply to author
Forward
0 new messages