From dbcdeec5d4d128e8dfa4fda206d0ba90dd4ffec9 Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Sat, 18 Nov 2023 04:19:56 +0100 Subject: [PATCH 1/3] feat(installation): add option to disable cloning the repository at install --- install.sh | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/install.sh b/install.sh index 5915a33d..e35686c2 100755 --- a/install.sh +++ b/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!" @@ -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" @@ -158,7 +188,16 @@ then Version="tags/${Version}" fi else - Version="tags/${Version}" + if [[ -e ".git/refs/tags/${Version}" ]] + 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..." From b0ddf4d704063b30772bd5a275f8411a15a09f84 Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Sat, 18 Nov 2023 04:26:19 +0100 Subject: [PATCH 2/3] fix(installation): avoid additional repository cloning in devcontainer setup closes #1776 --- .devcontainer/setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh index 0e090a86..c119ab81 100755 --- a/.devcontainer/setup.sh +++ b/.devcontainer/setup.sh @@ -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 From 5baa7c2d62c3b4c9131f842af3ca5073005aa46e Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Sat, 18 Nov 2023 23:46:43 +0100 Subject: [PATCH 3/3] fix(installation): cargo path in devcontainer commands --- .devcontainer/devcontainer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index e1b2cec1..7f3b78d9 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -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": {