install_nvm_from_git
This file
Path
test/install_script/install_nvm_from_git
138 lines · 4.5 KiB
Last changed by
[Tests] install_nvm_from_git: don't fail when master is at the latest release tagJordan Harbandbefore adoption52047ed
History of this fileTake it
The walk stopped after 200 commits: lines older than 5c12680 point at it.
[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680
lines 1–19why, one step back1#!/bin/sh23SAVE_NVM_DIR="$NVM_DIR"4SAVE_NVM_INSTALL_VERSION="$NVM_INSTALL_VERSION"56cleanup () {7 NVM_DIR="$SAVE_NVM_DIR"8 NVM_INSTALL_VERSION="$SAVE_NVM_INSTALL_VERSION"9 unset SAVE_NVM_DIR SAVE_NVM_INSTALL_VERSION10 unset -f die cleanup test_step get_head_ref get_head_changeset get_fetch_head_changeset \11 step_to_previous_changeset test_install_data test_install12}1314die () { echo -e "$@" ; cleanup ; exit 1; }1516NVM_ENV=testing \. ../../install.sh1718set -ex19[Tests] `install_nvm_from_git`: stop git background gc/maintenance racing with cleanupJordan Harbandbefore adoption84079db
lines 20–22why, one step back20git config --global gc.autoDetach false21git config --global maintenance.auto false22[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680
lines 23–65why, one step back23# nvm_do_install is available24type install_nvm_from_git > /dev/null 2>&1 || die 'install_nvm_from_git is not available'2526test_step() {27 echo -e "\e[33m$*\e[0m"28}2930get_head_ref(){31 git --git-dir "$NVM_DIR"/.git --no-pager log --pretty=format:'%d' -132}3334get_head_changeset() {35 git --git-dir "$NVM_DIR"/.git rev-parse --verify HEAD36}3738get_fetch_head_changeset() {39 git --git-dir "$NVM_DIR"/.git rev-parse --verify FETCH_HEAD40}4142step_to_previous_changeset() {43 git --git-dir "$NVM_DIR"/.git fetch origin +"$(get_head_changeset)" --depth=244 git --git-dir "$NVM_DIR"/.git reset --hard HEAD~145}4647# args:48# - 1: current ref49# - 2: current changeset50# - 3: error message51# - 4: ref to check ("" if none)52# - 5: changeset to check ("" if none)53# - 6: ref to avoid ("" if none)54test_install_data() {55 local current_ref="$1"56 local current_changeset="$2"57 local message="$3"58 local ref="$4"59 local changeset="$5"60 local avoid_ref="$6"6162 if [ -n "$ref" ]; then63 echo "$current_ref" | grep -q "$ref" || die "install_nvm_from_git ${message} did not clone with ref ${ref}"64 fi65[Tests] install_nvm_from_git: don't fail when master is at the latest release tagJordan Harbandbefore adoption52047ed
lines 66–74why, one step back66 if [ -n "${avoid_ref}" ] && echo "${current_ref}" | grep -q "${avoid_ref}"; then67 # the avoided tag decorating HEAD is only legitimate if HEAD really is that68 # tag's commit in the installed clone (eg master released at that tag); query69 # the clone itself, not the caller's checkout, so the trigger ref cannot skew it70 local avoid_changeset71 avoid_changeset="$(git --git-dir "$NVM_DIR"/.git rev-parse --verify --quiet "refs/tags/${avoid_ref}^{commit}" 2>/dev/null)"72 if [ "${avoid_changeset}" != "${current_changeset}" ]; then73 die "install_nvm_from_git ${message} did clone with unwanted ref ${avoid_ref}"74 fi[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680
lines 75–105why, one step back75 fi7677 if [ -n "$changeset" ]; then78 echo "${current_changeset}" | grep -q "${changeset}" || die "install_nvm_from_git ${message} did not clone with changeset ${changeset}"79 fi80}8182# args:83# - 1: version to install ("" for latest, tag, ref or changeset)84# - 2: error message85# - 3: ref to check ("" if none)86# - 4: changeset to check ("" if none)87# - 5: ref to avoid ("" if none)88test_install() {89 if [ -n "${1-}" ]; then90 export NVM_INSTALL_VERSION="$1"91 else92 unset NVM_INSTALL_VERSION93 fi94 local message="$2"95 local ref="$3"96 local changeset="$4"97 local avoid_ref="$5"9899 NVM_DIR=$(mktemp -d) || die 'Unable to create temporary directory'100 NVM_DIR="$NVM_DIR/clone"101102 # Ensure it clones the repository for non existing directory103 test_step "Clones repo $message"104 install_nvm_from_git105 test_install_data "$(get_head_ref)" "$(get_head_changeset)" "$message" "$ref" "$changeset" "$avoid_ref"[Tests] `install_nvm_from_git`: stop git background gc/maintenance racing with cleanupJordan Harbandbefore adoption84079db
line 106why, one step back106 rm -rf "$NVM_DIR" || { sleep 1; rm -rf "$NVM_DIR"; }[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680
lines 107–112why, one step back107108 # Ensure it initializes the repository for an empty existing repository109 mkdir -p "$NVM_DIR" || die 'Unable to create directory'110 test_step "Initialize repo $message"111 install_nvm_from_git112 test_install_data "$(get_head_ref)" "$(get_head_changeset)" "$message" "$ref" "$changeset" "$avoid_ref"[Tests] `install_nvm_from_git`: stop git background gc/maintenance racing with cleanupJordan Harbandbefore adoption84079db
line 113why, one step back113 rm -rf "$NVM_DIR" || { sleep 1; rm -rf "$NVM_DIR"; }[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680
lines 114–120why, one step back114115 # Ensure it updates the repository for an existing git repository116 git clone "$(nvm_source "git")" -b "v0.36.0" --depth=2 "$NVM_DIR" || die 'Unable to clone repository'117 step_to_previous_changeset118 test_step "Updates repo $message"119 install_nvm_from_git120 test_install_data "$(get_head_ref)" "$(get_head_changeset)" "$message" "$ref" "$changeset" "$avoid_ref"[Tests] `install_nvm_from_git`: stop git background gc/maintenance racing with cleanupJordan Harbandbefore adoption84079db
line 121why, one step back121 rm -rf "$NVM_DIR" || { sleep 1; rm -rf "$NVM_DIR"; }[Dev Deps] update `markdown-link-check`Jordan Harbandbefore adoption5c12680
lines 122–138why, one step back122}123124# Handle latest version125test_install "" "latest version" "$(nvm_latest_version)"126127# Handle given changeset128changeset="3abb98124e8d30c9652976c9d34a7380036083b5"129test_install "$changeset" "with changeset $changeset" "" "$changeset" "$(nvm_latest_version)"130131# Handle given tag132test_install "v0.37.0" "version v0.37.0" "v0.37.0" "4054bd70cedb9998015c2d8cc468c818c7d2f57d" "$(nvm_latest_version)"133134# Handle given ref135test_install "refs/pull/2397/head" "with refs/pull/2397/head" "" "9849bf494d50e74aa810451fb1f83208b0092dd6" "$(nvm_latest_version)"136test_install "master" "master" "" "" "$(nvm_latest_version)"137138cleanup