mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-12-06 22:52:23 +03:00
[Fix] install.sh: abort when adding the required Git remote fails
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
This commit is contained in:
1 parent
6c74a83e52
commit
2f736f5781
2 files changed
+31
-1
No files matched your search
+1
-1
@@ -197,7 +197,7 @@ install_nvm_from_git() {
|
||||
NVM_REMOTE_SUFFIX=$((NVM_REMOTE_SUFFIX + 1))
|
||||
NVM_REMOTE_NAME="nvm-origin-${NVM_REMOTE_SUFFIX}"
|
||||
done
|
||||
command git --git-dir="${INSTALL_DIR}/.git" remote add "${NVM_REMOTE_NAME}" "${NVM_GIT_SOURCE}" || return 2
|
||||
command git --git-dir="${INSTALL_DIR}/.git" remote add "${NVM_REMOTE_NAME}" "${NVM_GIT_SOURCE}" || exit 2
|
||||
fi
|
||||
else
|
||||
fetch_error="Failed to fetch origin with $NVM_VERSION. Please report this!"
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
#!/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
|
||||
Reference in new issue
Block a user