tools: post-pull auto-setup hook + caveman (RTK-style token optimization)
This commit is contained in:
@@ -12,12 +12,18 @@ CONTEXT_DIR="${HOMELAB_CONTEXT_DIR:-/opt/homelab-context}"
|
||||
|
||||
# Git safe.directory workaround: the repo is owned by the regular user
|
||||
# but launchd runs as root. Run git as the repo owner.
|
||||
REPO_OWNER=$(stat -f "%Su" "$(readlink -f "$CONTEXT_DIR")" 2>/dev/null || \
|
||||
stat -f "%Su" "/Users/dtoro/Homelab-Docs" 2>/dev/null || echo "root")
|
||||
if command -v realpath &>/dev/null; then
|
||||
REPO_REAL=$(realpath "$CONTEXT_DIR")
|
||||
elif command -v grealpath &>/dev/null; then
|
||||
REPO_REAL=$(grealpath "$CONTEXT_DIR")
|
||||
else
|
||||
REPO_REAL=$(perl -e 'print Cwd::abs_path(shift)' "$CONTEXT_DIR" 2>/dev/null || echo "/Users/dtoro/Homelab-Docs")
|
||||
fi
|
||||
REPO_OWNER=$(stat -f "%Su" "$REPO_REAL" 2>/dev/null || echo "dtoro")
|
||||
|
||||
# 1. Git pull (as repo owner to avoid safe.directory issues)
|
||||
if [ "$REPO_OWNER" != "root" ] && command -v sudo &>/dev/null; then
|
||||
sudo -u "$REPO_OWNER" git -C "$CONTEXT_DIR" pull --ff-only --quiet 2>&1 || \
|
||||
sudo -u "$REPO_OWNER" git -C "$CONTEXT_DIR" pull --ff-only --quiet 2>&1 | grep -v "failed to store" || \
|
||||
echo "[post-pull] git pull failed (network?) continuing..."
|
||||
else
|
||||
git -C "$CONTEXT_DIR" pull --ff-only --quiet 2>&1 || \
|
||||
|
||||
Reference in New Issue
Block a user