Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clippy codespaces fix #1780

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Expand Up @@ -2,10 +2,10 @@
"image": "mcr.microsoft.com/devcontainers/universal:2-linux",
"waitFor": "onCreateCommand",
"onCreateCommand": ".devcontainer/setup.sh",
"updateContentCommand": "cargo build",
"updateContentCommand": ". $HOME/.cargo/env && cargo build",
"postCreateCommand": "",
"postAttachCommand": {
"server": "rustlings watch"
"server": ". $HOME/.cargo/env && rustlings watch"
},
"customizations": {
"vscode": {
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/setup.sh
Expand Up @@ -4,4 +4,4 @@ curl https://sh.rustup.rs -sSf | sh -s -- -y
# Update current shell environment variables after install to find rustup
. "$HOME/.cargo/env"
rustup install stable
bash install.sh
bash install.sh --no-clone
49 changes: 44 additions & 5 deletions install.sh
@@ -1,5 +1,19 @@
#!/usr/bin/env bash
set -euo pipefail
NoClone=false

while getopts :n-: OPT; do
if [ "$OPT" = "-" ]; then
OPT="${OPTARG%%=*}"
fi

case "$OPT" in
n | no-clone ) NoClone=true ;;
??* ) echo "Invalid option --$OPT" >&2; exit 1;;
\? ) echo "Invalid option -$OPTARG" >&2; exit 1;;
esac
done
shift $((OPTIND - 1))

echo -e "\nLet's get you set up with Rustlings!"

Expand Down Expand Up @@ -135,11 +149,27 @@ else
echo "SUCCESS: Rust is up to date"
fi

Path=${1:-rustlings/}
echo "Cloning Rustlings at $Path..."
git clone -q https://github.com/rust-lang/rustlings "$Path"
if [[ "$NoClone" = true ]]
then
echo "Checking if already inside Rustlings directory..."
if ! [[ -e info.toml ]]
then
echo "ERROR: Not inside the Rustlings base directory, no 'info.toml' found"
echo "Please navigate inside the Rustlings base directory"
fi
GitRepository=$(git rev-parse --is-inside-work-tree)
if ! [[ "$GitRepository" = true ]]
then
echo "ERROR: Directory is not a Git repository"
echo "Please clone the Rustlings repository or run the installer wihtout the '--no-clone' option"
fi
else
Path=${1:-rustlings/}
echo "Cloning Rustlings at $Path..."
git clone -q https://github.com/rust-lang/rustlings "$Path"

cd "$Path"
cd "$Path"
fi

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']) if 'tag_name' in obj else sys.exit(f\"Error: {obj['message']}\");")
CargoBin="${CARGO_HOME:-$HOME/.cargo}/bin"
Expand All @@ -158,7 +188,16 @@ then
Version="tags/${Version}"
fi
else
Version="tags/${Version}"
if [[ -e ".git/refs/tags/${Version}" ]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this'll always fail because it's not in the Rustlings directory at this time (for normal invocations of the script)

then
Version="tags/${Version}"
else
echo "ERROR: The latest tag from remote is not present in the local repository"
echo "You can fetch the repository information by running `git fetch --tags https://github.com/rust-lang/rustlings.git`"
echo "After that you can finish the installation by running `./install.sh --no-clone` again"
exit 1
fi

fi

echo "Checking out version $Version..."
Expand Down