fix(installer): honor git install versions

This commit is contained in:
Peter Steinberger
2026-05-13 13:17:07 +01:00
parent f91de52f0d
commit d1fdd6e186
6 changed files with 357 additions and 14 deletions
+125 -7
View File
@@ -1910,6 +1910,122 @@ run_pnpm() {
"${PNPM_CMD[@]}" "$@"
}
resolve_git_openclaw_ref() {
local requested="${OPENCLAW_VERSION:-latest}"
local resolved_version=""
case "$requested" in
""|latest)
resolved_version="$(npm view "openclaw" "dist-tags.${requested:-latest}" 2>/dev/null || true)"
if [[ -n "$resolved_version" ]]; then
echo "v${resolved_version}"
return 0
fi
echo "main"
return 0
;;
next|beta)
resolved_version="$(npm view "openclaw" "dist-tags.${requested:-latest}" 2>/dev/null || true)"
if [[ -n "$resolved_version" ]]; then
echo "v${resolved_version}"
return 0
fi
echo "$requested"
return 0
;;
main)
echo "main"
return 0
;;
v[0-9]*)
echo "$requested"
return 0
;;
[0-9]*.[0-9]*.[0-9]*)
echo "v${requested}"
return 0
;;
*)
echo "$requested"
return 0
;;
esac
}
checkout_git_openclaw_ref() {
local repo_dir="$1"
local ref="$2"
if [[ -z "$ref" ]]; then
return 0
fi
run_quiet_step "Fetching requested version" git -C "$repo_dir" fetch --tags origin
if [[ "$ref" == "main" ]]; then
run_quiet_step "Checking out main" git -C "$repo_dir" checkout main
if [[ "$GIT_UPDATE" == "1" ]]; then
run_quiet_step "Updating repository" git -C "$repo_dir" pull --rebase || true
fi
return 0
fi
if git -C "$repo_dir" rev-parse --verify --quiet "refs/tags/${ref}^{commit}" >/dev/null; then
run_quiet_step "Checking out ${ref}" git -C "$repo_dir" checkout --detach "$ref"
return 0
fi
if git -C "$repo_dir" ls-remote --exit-code --heads origin "$ref" >/dev/null 2>&1; then
run_quiet_step "Checking out ${ref}" git -C "$repo_dir" checkout -B "$ref" "origin/$ref"
if [[ "$GIT_UPDATE" == "1" ]]; then
run_quiet_step "Updating repository" git -C "$repo_dir" pull --rebase || true
fi
return 0
fi
if git -C "$repo_dir" rev-parse --verify --quiet "${ref}^{commit}" >/dev/null; then
run_quiet_step "Checking out ${ref}" git -C "$repo_dir" checkout --detach "$ref"
return 0
fi
ui_error "Requested git version not found: ${ref}"
return 1
}
repo_pnpm_spec() {
local repo_dir="$1"
local package_json="${repo_dir}/package.json"
if [[ ! -f "$package_json" ]]; then
return 1
fi
sed -n -E 's/^[[:space:]]*"packageManager"[[:space:]]*:[[:space:]]*"([^"]+)".*/\1/p' "$package_json" | head -n1
}
activate_repo_pnpm_version() {
local repo_dir="$1"
local spec version
spec="$(repo_pnpm_spec "$repo_dir" || true)"
if [[ "$spec" != pnpm@* ]]; then
return 0
fi
version="${spec#pnpm@}"
version="${version%%+*}"
if [[ -z "$version" ]]; then
return 0
fi
if command -v corepack >/dev/null 2>&1; then
ui_info "Activating repo pnpm ${version}"
corepack prepare "pnpm@${version}" --activate >/dev/null 2>&1 || true
refresh_shell_command_cache
detect_pnpm_cmd || true
fi
}
ensure_user_local_bin_on_path() {
local target="$HOME/.local/bin"
mkdir -p "$target"
@@ -2240,17 +2356,19 @@ install_openclaw_from_git() {
run_quiet_step "Cloning OpenClaw" git clone "$repo_url" "$repo_dir"
fi
if [[ "$GIT_UPDATE" == "1" ]]; then
if [[ -z "$(git -C "$repo_dir" status --porcelain 2>/dev/null || true)" ]]; then
run_quiet_step "Updating repository" git -C "$repo_dir" pull --rebase || true
else
ui_info "Repo has local changes; skipping git pull"
fi
local git_ref
git_ref="$(resolve_git_openclaw_ref)"
if [[ -z "$(git -C "$repo_dir" status --porcelain 2>/dev/null || true)" ]]; then
ui_info "Using git ref: ${git_ref}"
checkout_git_openclaw_ref "$repo_dir" "$git_ref"
else
ui_info "Repo has local changes; skipping git checkout/update"
fi
cleanup_legacy_submodules "$repo_dir"
activate_repo_pnpm_version "$repo_dir"
SHARP_IGNORE_GLOBAL_LIBVIPS="$SHARP_IGNORE_GLOBAL_LIBVIPS" run_quiet_step "Installing dependencies" run_pnpm -C "$repo_dir" install
SHARP_IGNORE_GLOBAL_LIBVIPS="$SHARP_IGNORE_GLOBAL_LIBVIPS" run_quiet_step "Installing dependencies" run_pnpm -C "$repo_dir" install --frozen-lockfile
if ! run_quiet_step "Building UI" run_pnpm -C "$repo_dir" ui:build; then
ui_warn "UI build failed; continuing (CLI may still work)"