Commit 41f7158f authored by Adrien Oliva's avatar Adrien Oliva

feat(installhook): Interactive hook installation

When hooks are already present in git dir, enter in interactive mode to
know what do.
Signed-off-by: Adrien Oliva's avatarAdrien Oliva <olivaa+gitlab@yapbreak.fr>
parent b68bccf1
......@@ -51,6 +51,75 @@ installfile()
src="$1"
dst="$2"
if [ -f "$dst" ]; then
if [ $SYMBOLIC -eq 0 ]; then
if diff "$src" "$dst" -q >/dev/null; then
echo "$dst already exists but is the same"
else
local _done
_done=0
while [ $_done -eq 0 ]; do
local ans
echo "$dst already exists what do?"
echo -n "(D)iff, (E)dit, (R)eplace, (S)kip "
read -r ans
case "$ans" in
D|d)
diff "$src" "$dst"
;;
E|e)
vimdiff "$src" "$dst"
_done=1
;;
R|r)
rm -f "$dst"
installfile "$src" "$dst"
_done=1
;;
S|s)
_done=1
;;
*)
echo "Cannot understand your answer"
;;
esac
done
fi
else
if [ "$(readlink -f "$src")" == "$(readlink -f "$dst")" ]; then
echo "$dst already a symbolic link to $src"
else
local _done
_done=0
while [ $_done -eq 0 ]; do
local ans
echo "$dst already exists what do?"
echo -n "(D)iff, (R)eplace, (S)kip "
read -r ans
case "$ans" in
D|d)
diff "$src" "$dst"
;;
R|r)
rm -f "$dst"
installfile "$src" "$dst"
_done=1
;;
S|s)
_done=1
;;
*)
echo "Cannot understand your answer"
;;
esac
done
fi
fi
sed 's|.|=|g' <<<"${dst}"
return $?
fi
# From this point, $dst does not exist
if [ $SYMBOLIC -eq 0 ]; then
cp -f "$src" "$dst"
else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment