mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-12-06 22:52:23 +03:00
An existing installation may need a new remote before it can fetch an update.
If adding that remote fails,
the helper returns 2 but the installer ignores it,
modifies the profile,
and can report success while still using the old version.
Exit at the failing command, consistent with other fatal Git errors.
Use a real Git config lock to exercise both installation methods.
Verify that the test reaches its intended failure rather than passing on an unrelated nonzero exit.
Regression introduced by dbda4b9387
31 lines
1.5 KiB
Bash
Executable File
31 lines
1.5 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
die () { echo "$@" ; exit 1; }
|
|
|
|
INSTALLER="$(dirname "$0")/../../install.sh"
|
|
|
|
TEST_DIR="$(mktemp -d)" || die 'Unable to create temporary directory'
|
|
trap 'rm -rf "${TEST_DIR}"' 0
|
|
export HOME="${TEST_DIR}"
|
|
export NVM_DIR="${TEST_DIR}/nvm"
|
|
export NVM_SOURCE="${TEST_DIR}/new-source"
|
|
export PROFILE="${TEST_DIR}/.bashrc"
|
|
unset NVM_ENV NVM_INSTALL_VERSION NVM_INSTALL_GITHUB_REPO NODE_VERSION
|
|
|
|
command git init -q "${NVM_DIR}" || die 'Unable to initialize repository'
|
|
command git --git-dir="${NVM_DIR}/.git" remote add origin "${TEST_DIR}/old-source" || die 'Unable to add origin'
|
|
# A concurrent git operation can prevent the installer from adding its remote.
|
|
: > "${NVM_DIR}/.git/config.lock" || die 'Unable to lock Git config'
|
|
: > "${PROFILE}" || die 'Unable to create profile'
|
|
# Record sourcing without invoking the system npm if the installer continues.
|
|
printf '%s\n' ': > "${NVM_DIR}/sourced"' 'nvm_check_global_modules() { return 0; }' > "${NVM_DIR}/nvm.sh" || die 'Unable to write nvm.sh'
|
|
|
|
for METHOD in '' git; do
|
|
EXIT_CODE=0
|
|
OUTPUT="$(METHOD="${METHOD}" LC_ALL=C bash +e "${INSTALLER}" 2>&1)" || EXIT_CODE=$?
|
|
[ "${EXIT_CODE}" = '2' ] || die "Expected exit 2 for METHOD=${METHOD}, got ${EXIT_CODE}: ${OUTPUT}"
|
|
printf '%s\n' "${OUTPUT}" | grep -q 'could not lock config file .*: File exists$' || die "Expected Git config lock error: ${OUTPUT}"
|
|
[ -f "${PROFILE}" ] && [ ! -s "${PROFILE}" ] || die 'The installer modified the profile after failing'
|
|
[ ! -e "${NVM_DIR}/sourced" ] || die 'The installer sourced nvm.sh after failing'
|
|
done
|