Skip to content

Commit 9e4fb10

Browse files
committed
fix(installation): Provide a backup git reference when tag can't be curl
closes rust-lang#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.
1 parent 8ad5f9b commit 9e4fb10

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

install.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,30 @@ Path=${1:-rustlings/}
102102
echo "Cloning Rustlings at $Path..."
103103
git clone -q https://github.com/rust-lang/rustlings $Path
104104

105+
cd $Path
106+
105107
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']);")
106108
CargoBin="${CARGO_HOME:-$HOME/.cargo}/bin"
107109

110+
if [[ -z ${Version} ]]
111+
then
112+
echo "The latest tag version could not be fetched remotely."
113+
echo "Using the local git repository..."
114+
Version=$(ls -tr .git/refs/tags/ | tail -1)
115+
if [[ -z ${Version} ]]
116+
then
117+
echo "No valid tag version found"
118+
echo "Rustlings will be installed using the master branch"
119+
Version="master"
120+
else
121+
Version="tags/${Version}"
122+
fi
123+
else
124+
Version="tags/${Version}"
125+
fi
126+
108127
echo "Checking out version $Version..."
109-
cd $Path
110-
git checkout -q tags/$Version
128+
git checkout -q ${Version}
111129

112130
echo "Installing the 'rustlings' executable..."
113131
cargo install --force --path .

0 commit comments

Comments
 (0)