#!/usr/bin/env bash set -euo pipefail usage() { cat <<'EOF' Usage: ./scripts/ensure-core-ide.sh [--fork-url ] [--upstream-url ] What it does: - Ensures the Lapce checkout exists at ./core_ide (ignored by the parent repo). - Optionally configures remotes for a fork workflow: - origin = fork (if --fork-url is provided) - upstream = official Lapce upstream (default: https://github.com/lapce/lapce.git) Notes: - This script does not write any secrets. - If you cloned with --depth 1 and need full history later: (cd core_ide && git fetch --unshallow) EOF } ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" CORE_IDE_DIR="${ROOT}/core_ide" FORK_URL="" UPSTREAM_URL="https://github.com/lapce/lapce.git" while [[ $# -gt 0 ]]; do case "$1" in -h|--help) usage exit 0 ;; --fork-url) FORK_URL="${2:-}" shift 2 ;; --upstream-url) UPSTREAM_URL="${2:-}" shift 2 ;; *) echo "Unknown argument: $1" >&2 usage >&2 exit 2 ;; esac done if [[ -d "${CORE_IDE_DIR}/.git" ]]; then echo "core_ide already exists: ${CORE_IDE_DIR}" else echo "core_ide missing; cloning..." mkdir -p "${ROOT}" if [[ -n "${FORK_URL}" ]]; then git clone --depth 1 "${FORK_URL}" "${CORE_IDE_DIR}" else git clone --depth 1 "${UPSTREAM_URL}" "${CORE_IDE_DIR}" fi fi if [[ ! -f "${CORE_IDE_DIR}/Cargo.toml" ]]; then echo "core_ide does not look like a Lapce checkout (missing Cargo.toml): ${CORE_IDE_DIR}" >&2 exit 1 fi ( cd "${CORE_IDE_DIR}" # Ensure upstream remote exists (official Lapce). if ! git remote get-url upstream >/dev/null 2>&1; then git remote add upstream "${UPSTREAM_URL}" fi if [[ -n "${FORK_URL}" ]]; then git remote set-url origin "${FORK_URL}" fi echo "Remotes:" git remote -v ) echo "OK"