Nico Huber has uploaded this change for review.
[WIP] git-hooks: Fix install script for various git versions
Change-Id: I7ee8d4d54db48f7207fe8abf895c7fbba7685ad2
Signed-off-by: Nico Huber <nico.h@gmx.de>
---
M util/git-hooks/install.sh
1 file changed, 15 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/71/22971/1
diff --git a/util/git-hooks/install.sh b/util/git-hooks/install.sh
index d557c2f..44ccc94 100755
--- a/util/git-hooks/install.sh
+++ b/util/git-hooks/install.sh
@@ -3,10 +3,23 @@
root=$(git rev-parse --show-cdup 2>/dev/null) || \
{ echo "Not under git control. Cannot install git hooks." >&2 ; exit 0 ; }
-dst="${root}"$(git rev-parse --git-path hooks/)
src=util/git-hooks/ # relative to root
hooks=$(cd "${root}${src}" && git ls-files -c | grep -Ev 'install.sh|wrapper.sh')
+if [ $(git rev-parse --git-path 2>/dev/null) = "--git-path" ]; then
+ # very old git, we have to guess
+ dst="${root}.git/hooks/"
+ rel="../../"
+elif [ $(cd "${root}${src}" && git rev-parse --git-path .) = \
+ $(cd "${root}" && git rev-parse --git-path .) ]; then
+ # broken --git-path
+ dst="${root}"$(git rev-parse --git-path hooks/)
+ rel=$(git rev-parse --prefix $(git rev-parse --git-path hooks/) --show-cdup)
+else
+ dst=$(git rev-parse --git-path hooks/)
+ rel=$(git rev-parse --prefix "${dst}" --show-cdup)
+fi
+
for h in $hooks; do
# Test if hook is not already installed, i.e. doesn't point at the wrapper
if [ ! "${dst}$h" -ef "${root}${src}wrapper.sh" ]; then
@@ -14,7 +27,6 @@
if [ -e "${dst}$h" ]; then
mv "${dst}$h" "${dst}$h.local"
fi
- ln -s "$(git rev-parse --prefix $(git rev-parse --git-path hooks/) --show-cdup)${src}wrapper.sh" \
- "${dst}$h"
+ ln -s "${rel}${src}wrapper.sh" "${dst}$h"
fi
done
To view, visit change 22971. To unsubscribe, or for help writing mail filters, visit settings.