























@@ -364,6 +364,128 @@ run_pnpm() {
364364"${PNPM_CMD[@]}" "$@"
365365}
366366367+resolve_git_openclaw_ref() {
368+local requested="${OPENCLAW_VERSION:-latest}"
369+local resolved_version=""
370+371+case "$requested" in
372+""|latest)
373+ resolved_version="$("$(npm_bin)" view "openclaw" "dist-tags.${requested:-latest}" 2>/dev/null || true)"
374+if [[ -n "$resolved_version" ]]; then
375+echo "v${resolved_version}"
376+return 0
377+fi
378+echo "main"
379+return 0
380+ ;;
381+ next|beta)
382+ resolved_version="$("$(npm_bin)" view "openclaw" "dist-tags.${requested:-latest}" 2>/dev/null || true)"
383+if [[ -n "$resolved_version" ]]; then
384+echo "v${resolved_version}"
385+return 0
386+fi
387+echo "$requested"
388+return 0
389+ ;;
390+ main)
391+echo "main"
392+return 0
393+ ;;
394+ v[0-9]*)
395+echo "$requested"
396+return 0
397+ ;;
398+ [0-9]*.[0-9]*.[0-9]*)
399+echo "v${requested}"
400+return 0
401+ ;;
402+*)
403+echo "$requested"
404+return 0
405+ ;;
406+esac
407+}
408+409+checkout_git_openclaw_ref() {
410+local repo_dir="$1"
411+local ref="$2"
412+413+if [[ -z "$ref" ]]; then
414+return 0
415+fi
416+417+ git -C "$repo_dir" fetch --tags origin
418+419+if [[ "$ref" == "main" ]]; then
420+ git -C "$repo_dir" checkout main
421+if [[ "$GIT_UPDATE" == "1" ]]; then
422+ git -C "$repo_dir" pull --rebase || true
423+fi
424+return 0
425+fi
426+427+if git -C "$repo_dir" rev-parse --verify --quiet "refs/tags/${ref}^{commit}" >/dev/null; then
428+ git -C "$repo_dir" checkout --detach "$ref"
429+return 0
430+fi
431+432+if git -C "$repo_dir" ls-remote --exit-code --heads origin "$ref" >/dev/null 2>&1; then
433+ git -C "$repo_dir" checkout -B "$ref" "origin/$ref"
434+if [[ "$GIT_UPDATE" == "1" ]]; then
435+ git -C "$repo_dir" pull --rebase || true
436+fi
437+return 0
438+fi
439+440+if git -C "$repo_dir" rev-parse --verify --quiet "${ref}^{commit}" >/dev/null; then
441+ git -C "$repo_dir" checkout --detach "$ref"
442+return 0
443+fi
444+445+ fail "Requested git version not found: ${ref}"
446+}
447+448+repo_pnpm_spec() {
449+local repo_dir="$1"
450+local package_json="${repo_dir}/package.json"
451+452+if [[ ! -f "$package_json" ]]; then
453+return 1
454+fi
455+456+ sed -n -E 's/^[[:space:]]*"packageManager"[[:space:]]*:[[:space:]]*"([^"]+)".*/\1/p' "$package_json" | head -n1
457+}
458+459+activate_repo_pnpm_version() {
460+local repo_dir="$1"
461+local spec
462+local version
463+local corepack_cmd=""
464+465+ spec="$(repo_pnpm_spec "$repo_dir" || true)"
466+if [[ "$spec" != pnpm@* ]]; then
467+return 0
468+fi
469+470+ version="${spec#pnpm@}"
471+ version="${version%%+*}"
472+if [[ -z "$version" ]]; then
473+return 0
474+fi
475+476+if [[ -x "$(node_dir)/bin/corepack" ]]; then
477+ corepack_cmd="$(node_dir)/bin/corepack"
478+elif command -v corepack >/dev/null 2>&1; then
479+ corepack_cmd="$(command -v corepack)"
480+fi
481+482+if [[ -n "$corepack_cmd" ]]; then
483+ log "Activating repo pnpm ${version}"
484+"$corepack_cmd" prepare "pnpm@${version}" --activate >/dev/null 2>&1 || true
485+ detect_pnpm_cmd || true
486+fi
487+}
488+367489install_node() {
368490local os
369491local arch
@@ -588,18 +710,20 @@ install_openclaw_from_git() {
588710 git clone "$repo_url" "$repo_dir"
589711fi
590712591-if [[ "$GIT_UPDATE" == "1" ]]; then
592-if [[ -z "$(git -C "$repo_dir" status --porcelain 2>/dev/null || true)" ]]; then
593- git -C "$repo_dir" pull --rebase || true
594-else
595- log "Repo is dirty; skipping git pull"
596-fi
713+local git_ref
714+ git_ref="$(resolve_git_openclaw_ref)"
715+if [[ -z "$(git -C "$repo_dir" status --porcelain 2>/dev/null || true)" ]]; then
716+ log "Using git ref: ${git_ref}"
717+ checkout_git_openclaw_ref "$repo_dir" "$git_ref"
718+else
719+ log "Repo is dirty; skipping git checkout/update"
597720fi
598721599722 cleanup_legacy_submodules "$repo_dir"
600723 ensure_pnpm_git_prepare_allowlist "$repo_dir"
724+ activate_repo_pnpm_version "$repo_dir"
601725602- SHARP_IGNORE_GLOBAL_LIBVIPS="$SHARP_IGNORE_GLOBAL_LIBVIPS" run_pnpm -C "$repo_dir" install
726+ SHARP_IGNORE_GLOBAL_LIBVIPS="$SHARP_IGNORE_GLOBAL_LIBVIPS" run_pnpm -C "$repo_dir" install --frozen-lockfile
603727604728if ! run_pnpm -C "$repo_dir" ui:build; then
605729 log "UI build failed; continuing (CLI may still work)"
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。