Skip to content

Commit 4078998

Browse files
Marcelo Silveiraclaude
authored andcommitted
use temp dir for doctor.sh curl | bash instead of persisting clone
Shallow-clone into a temp directory with trap-based cleanup so doctor remains truly side-effect-free. Reuses ~/Work/setup when it already exists. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ab224f6 commit 4078998

1 file changed

Lines changed: 14 additions & 26 deletions

File tree

doctor.sh

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,25 @@ set -uo pipefail
2525
if [ -n "${BASH_SOURCE[0]:-}" ] && [ -f "${BASH_SOURCE[0]}" ]; then
2626
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2727
else
28-
# Running via curl | bash — clone (or update) the repo at ~/Work/setup
29-
SETUP_CLONE_DIR="$HOME/Work/setup"
28+
# Running via curl | bash — need the repo for lib/ scripts.
29+
# Use the existing local clone if available, otherwise shallow-clone
30+
# into a temp directory and clean it up on exit.
3031
SETUP_REPO="${SETUP_REPO:-trusted/setup}"
3132
SETUP_REF="${SETUP_REF:-main}"
33+
DOCTOR_TMPDIR=""
3234

33-
if [ -d "$SETUP_CLONE_DIR/.git" ]; then
34-
# Abort if there are uncommitted changes
35-
if ! git -C "$SETUP_CLONE_DIR" diff --quiet HEAD 2>/dev/null; then
36-
echo "ERROR: $SETUP_CLONE_DIR has uncommitted changes."
37-
echo "Commit or stash them, then re-run doctor."
38-
exit 1
39-
fi
40-
41-
# Abort if on the wrong branch
42-
local_branch="$(git -C "$SETUP_CLONE_DIR" branch --show-current)"
43-
if [ "$local_branch" != "$SETUP_REF" ]; then
44-
echo "ERROR: $SETUP_CLONE_DIR is on branch '$local_branch', expected '$SETUP_REF'."
45-
echo "Switch to $SETUP_REF, then re-run doctor."
46-
exit 1
47-
fi
48-
49-
echo "Updating setup from github.com/$SETUP_REPO ($SETUP_REF)..."
50-
git -C "$SETUP_CLONE_DIR" pull --ff-only --quiet
35+
cleanup_tmp() { [ -n "$DOCTOR_TMPDIR" ] && rm -rf "$DOCTOR_TMPDIR"; }
36+
trap cleanup_tmp EXIT
37+
38+
if [ -d "$HOME/Work/setup/.git" ]; then
39+
SCRIPT_DIR="$HOME/Work/setup"
5140
else
52-
echo "Cloning setup from github.com/$SETUP_REPO ($SETUP_REF)..."
53-
mkdir -p "$HOME/Work"
54-
git clone "https://github.com/$SETUP_REPO.git" "$SETUP_CLONE_DIR" --quiet
55-
git -C "$SETUP_CLONE_DIR" checkout "$SETUP_REF" --quiet
41+
DOCTOR_TMPDIR="$(mktemp -d)"
42+
echo "Fetching setup from github.com/$SETUP_REPO ($SETUP_REF)..."
43+
git clone --depth 1 --branch "$SETUP_REF" \
44+
"https://github.com/$SETUP_REPO.git" "$DOCTOR_TMPDIR" --quiet
45+
SCRIPT_DIR="$DOCTOR_TMPDIR"
5646
fi
57-
58-
SCRIPT_DIR="$SETUP_CLONE_DIR"
5947
fi
6048

6149
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)