git-hooks: overwrite the windows-links not with linux-links

Always when you call build or logerrit, then the windows-links
overwrite with linux-links, but when you using GIT for Windows
you need the windows-links.
This patch made a check it is using GIT for Windows, and check what
for link it is, when wrong link, it output the .git-hooks/README

Improve the check for links, when a link is set not need to set
the link anymore

In .git-hooks/README improve the FOR with delete of the wrong link

look here for GIT for Windows:
https://wiki.documentfoundation.org/Development/BuildingOnWindows/de#Cygwin_and_git

Change-Id: I9f6ef9aca316058ef74cb2b2d107236f03a2e2ee
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147458
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
This commit is contained in:
Juergen Funk
2023-02-22 12:15:06 +01:00
committed by Thorsten Behrens
parent e32dfaf155
commit 9afc6b22e2
2 changed files with 49 additions and 17 deletions

View File

@@ -7,7 +7,7 @@ To install manually, run:
When you using GIT for Windows, you need Windows links When you using GIT for Windows, you need Windows links
Open a Dos-Box with admin rights then Open a Dos-Box with admin rights then
cd .git/hooks cd .git/hooks
FOR /F " usebackq " %i IN (`dir /b ..\..\.git-hooks`) DO mklink %i ..\..\.git-hooks\%i FOR /F " usebackq " %i IN (`dir /b ..\..\.git-hooks`) DO del /as /f %i & mklink %i ..\..\.git-hooks\%i
There are two groups of these hooks: client side and server side. There are two groups of these hooks: client side and server side.

64
g
View File

@@ -42,7 +42,7 @@ refresh_submodule_hooks()
continue continue
fi fi
hook="${repo?}/.git/hooks/${hook_name##*/}" hook="${repo?}/.git/hooks/${hook_name##*/}"
if [ ! -e "${hook?}" ] || [ -L "${hook?}" ] ; then if [ ! -e "${hook?}" ] || [ ! -L "${hook?}" ] ; then
rm -f "${hook?}" rm -f "${hook?}"
ln -sf "${hook_name}" "${hook?}" ln -sf "${hook_name}" "${hook?}"
fi fi
@@ -53,7 +53,7 @@ refresh_submodule_hooks()
continue continue
fi fi
hook="${repo?}/.git/hooks/${hook_name##*/}" hook="${repo?}/.git/hooks/${hook_name##*/}"
if [ ! -e "${hook?}" ] || [ -L "${hook?}" ] ; then if [ ! -e "${hook?}" ] || [ ! -L "${hook?}" ] ; then
rm -f "${hook?}" rm -f "${hook?}"
ln -sf "${hook_name}" "${hook?}" ln -sf "${hook_name}" "${hook?}"
fi fi
@@ -64,7 +64,7 @@ refresh_submodule_hooks()
continue continue
fi fi
hook=".git/modules/${repo?}/hooks/${hook_name##*/}" hook=".git/modules/${repo?}/hooks/${hook_name##*/}"
if [ ! -e "${hook?}" ] || [ -L "${hook?}" ] ; then if [ ! -e "${hook?}" ] || [ ! -L "${hook?}" ] ; then
rm -f "${hook?}" rm -f "${hook?}"
ln -sf "${hook_name}" "${hook?}" ln -sf "${hook_name}" "${hook?}"
fi fi
@@ -75,7 +75,7 @@ refresh_submodule_hooks()
continue continue
fi fi
hook=".git/modules/${repo?}/hooks/${hook_name##*/}" hook=".git/modules/${repo?}/hooks/${hook_name##*/}"
if [ ! -e "${hook?}" ] || [ -L "${hook?}" ] ; then if [ ! -e "${hook?}" ] || [ ! -L "${hook?}" ] ; then
rm -f "${hook?}" rm -f "${hook?}"
ln -sf "${hook_name}" "${hook?}" ln -sf "${hook_name}" "${hook?}"
fi fi
@@ -89,22 +89,44 @@ refresh_all_hooks()
local repo local repo
local hook_name local hook_name
local hook local hook
local winlnk
local lnkfile=".git/hooks/pre-commit"
pushd "${COREDIR?}" > /dev/null pushd "${COREDIR?}" > /dev/null
# There's no ".git" e.g. in a secondary worktree
if [ -d ".git" ]; then if [ $WINGIT -eq 1 ]; then
for hook_name in "${COREDIR?}/.git-hooks"/* ; do winlnk=0
hook=".git/hooks/${hook_name##*/}" if [ -e "${lnkfile}" ] && [ -L "${lnkfile}" ] ; then
if [ ! -e "${hook?}" ] || [ -L "${hook?}" ] ; then # if linux-links or windows-links?
rm -f "${hook?}" # dos dir output windows link:
ln -sf "${hook_name}" "${hook?}" # 04.09.2020 10:54 <SYMLINK> pre-commit [..\..\.git-hooks\pre-commit]
fi # dos dir output linux link:
# file not found
winlnk=$(cmd /C "DIR ${lnkfile//'/'/'\'}" 2>&1)
winlnk=$(echo "$winlnk" | grep -icE "<SYMLINK>.*${lnkfile##*/} \[")
fi
if [ $winlnk -eq 0 ]; then
echo "You using GIT for Windows, but the hook-links not right, change with mklink"
cat .git-hooks/README
fi
else
# There's no ".git" e.g. in a secondary worktree
if [ -d ".git" ]; then
for hook_name in "${COREDIR?}/.git-hooks"/* ; do
hook=".git/hooks/${hook_name##*/}"
if [ ! -e "${hook?}" ] || [ ! -L "${hook?}" ] ; then
rm -f "${hook?}"
ln -sf "${hook_name}" "${hook?}"
fi
done
fi
for repo in ${SUBMODULES_ALL?} ; do
refresh_submodule_hooks "$repo"
done done
fi fi
for repo in ${SUBMODULES_ALL?} ; do
refresh_submodule_hooks "$repo"
done
popd > /dev/null popd > /dev/null
} }
@@ -294,7 +316,9 @@ if [ "$#" -eq "0" ] ; then
usage usage
fi fi
if [ ! "$(type -p git)" ]; then gitfile="$(type -p git)"
if [ ! "${gitfile}" ]; then
echo "Cannot find the git binary! Is git installed and is in PATH?" echo "Cannot find the git binary! Is git installed and is in PATH?"
exit 1 exit 1
fi fi
@@ -323,6 +347,14 @@ REPORT_REPOS=1
REPORT_COMMANDS=0 REPORT_COMMANDS=0
REPORT_COMPACT=0 REPORT_COMPACT=0
DO_HOOK_REFRESH=false DO_HOOK_REFRESH=false
WINGIT=
# it is 'GIT for Windows'
WINGIT=$(echo $gitfile | grep -c cygdrive)
if [ $WINGIT -eq 1 ]; then
gitfile=$(git --version)
WINGIT=$(echo $gitfile | grep -ic windows)
fi
while [ "${COMMAND:0:1}" = "-" ] ; do while [ "${COMMAND:0:1}" = "-" ] ; do
case "$COMMAND" in case "$COMMAND" in