mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-26 23:36:30 +00:00
fix(installation): Provide a backup git reference when tag can't be curl
closes #423 If the parsed JSON data curled during a bash installation is not valid, use the repository's tag files as a backup. If those files don't exist somehow, then checkout the master branch and install it.
This commit is contained in:
parent
8ad5f9bf53
commit
9e4fb1009f
1 changed files with 20 additions and 2 deletions
22
install.sh
22
install.sh
|
@ -102,12 +102,30 @@ Path=${1:-rustlings/}
|
||||||
echo "Cloning Rustlings at $Path..."
|
echo "Cloning Rustlings at $Path..."
|
||||||
git clone -q https://github.com/rust-lang/rustlings $Path
|
git clone -q https://github.com/rust-lang/rustlings $Path
|
||||||
|
|
||||||
|
cd $Path
|
||||||
|
|
||||||
Version=$(curl -s https://api.github.com/repos/rust-lang/rustlings/releases/latest | ${PY} -c "import json,sys;obj=json.load(sys.stdin);print(obj['tag_name']);")
|
Version=$(curl -s https://api.github.com/repos/rust-lang/rustlings/releases/latest | ${PY} -c "import json,sys;obj=json.load(sys.stdin);print(obj['tag_name']);")
|
||||||
CargoBin="${CARGO_HOME:-$HOME/.cargo}/bin"
|
CargoBin="${CARGO_HOME:-$HOME/.cargo}/bin"
|
||||||
|
|
||||||
|
if [[ -z ${Version} ]]
|
||||||
|
then
|
||||||
|
echo "The latest tag version could not be fetched remotely."
|
||||||
|
echo "Using the local git repository..."
|
||||||
|
Version=$(ls -tr .git/refs/tags/ | tail -1)
|
||||||
|
if [[ -z ${Version} ]]
|
||||||
|
then
|
||||||
|
echo "No valid tag version found"
|
||||||
|
echo "Rustlings will be installed using the master branch"
|
||||||
|
Version="master"
|
||||||
|
else
|
||||||
|
Version="tags/${Version}"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
Version="tags/${Version}"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Checking out version $Version..."
|
echo "Checking out version $Version..."
|
||||||
cd $Path
|
git checkout -q ${Version}
|
||||||
git checkout -q tags/$Version
|
|
||||||
|
|
||||||
echo "Installing the 'rustlings' executable..."
|
echo "Installing the 'rustlings' executable..."
|
||||||
cargo install --force --path .
|
cargo install --force --path .
|
||||||
|
|
Loading…
Reference in a new issue