unset GIT_DIR
# If .git/ subdirectory is already here
-test -d .git && exit 0
+[ -d .git ] && exit 0
-if ! test -f .git; then
+if ! [ -f .git ]; then
echo "Error: Cannot find gitlink, aborting" >&2
exit 1
fi
git config --unset core.worktree
read _gitdir gitpath < .git
+if [ "$_gitdir" != gitdir: ]; then
+ echo "Error: Bad gitlink, aborting" >&2
+ exit 1
+fi
unset _gitdir
rm .git
exec mv "$gitpath" .git