#!/usr/bin/env sh set -eu REPO_URL="${REPO_URL:-http://100.64.0.1:30087/section0/rta-handbook.git}" TARGET_DIR="${TARGET_DIR:-$HOME/Developer/Section0/rta-handbook}" COMMAND_DIR="${COMMAND_DIR:-$HOME/.local/bin}" COMMAND_NAME="${COMMAND_NAME:-section0-docs}" COMMAND_PATH="$COMMAND_DIR/$COMMAND_NAME" step() { printf "\n==> %s\n" "$*" } if ! command -v git >/dev/null 2>&1; then echo "git is required but was not found on PATH" >&2 exit 1 fi step "Preparing local Markdown workspace" if [ -d "$TARGET_DIR/.git" ]; then echo "Repo already exists: $TARGET_DIR" git -C "$TARGET_DIR" remote set-url origin "$REPO_URL" git -C "$TARGET_DIR" fetch origin git -C "$TARGET_DIR" checkout main git -C "$TARGET_DIR" pull --ff-only else mkdir -p "$(dirname "$TARGET_DIR")" git clone "$REPO_URL" "$TARGET_DIR" fi git -C "$TARGET_DIR" config pull.ff only step "Installing helper command" mkdir -p "$COMMAND_DIR" cat > "$COMMAND_PATH" <&2 exit 1 fi if [ -n "\$author_email" ]; then git -C "\$REPO_DIR" config user.email "\$author_email" elif [ -z "\$current_email" ]; then echo "Git author email is required" >&2 exit 1 fi ;; doctor) remote="\$(git -C "\$REPO_DIR" remote get-url origin)" branch="\$(git -C "\$REPO_DIR" branch --show-current)" author_name="\$(git -C "\$REPO_DIR" config user.name || true)" author_email="\$(git -C "\$REPO_DIR" config user.email || true)" echo "Repo: \$REPO_DIR" echo "Remote: \$remote" echo "Branch: \$branch" if [ -n "\$author_name" ] && [ -n "\$author_email" ]; then echo "Git author: \$author_name <\$author_email>" else echo "Git author: missing; run section0-docs configure" fi git -C "\$REPO_DIR" ls-remote --heads origin main >/dev/null echo "Read access: ok" ;; open) printf "%s\n" "\$REPO_DIR" ;; pull) git -C "\$REPO_DIR" pull --ff-only ;; status) git -C "\$REPO_DIR" status --short --branch ;; commit) : "\${MESSAGE:?Set MESSAGE before running commit}" git -C "\$REPO_DIR" add . git -C "\$REPO_DIR" commit -m "\$MESSAGE" ;; push) git -C "\$REPO_DIR" push ;; push-test) branch="section0-smoke-\${USER:-user}-\$(date +%Y%m%d%H%M%S)" git -C "\$REPO_DIR" push origin HEAD:refs/heads/"\$branch" git -C "\$REPO_DIR" push origin :refs/heads/"\$branch" echo "Write access: ok" ;; help|--help|-h) usage ;; *) usage >&2 exit 1 ;; esac EOF chmod +x "$COMMAND_PATH" cat <