From 0273515951e40269405d66deb2b852dbae66e3c1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 11 Jan 2026 20:11:12 +0000 Subject: [PATCH] Add robust command availability checks to all shell scripts - Add check for @defaultPackageName@-devenv in activateDevenv.sh - Add check for uv command in initPython.sh - Add check for git command in initProject.sh (with graceful degradation) - Add checks for wget, sed, nix in updateDeps.sh - Provide clear error messages when commands are not available - Prevent scripts from failing with cryptic errors when tools are missing Co-authored-by: dwinkler1 <22460147+dwinkler1@users.noreply.github.com> --- templates/rde/scripts/activateDevenv.sh | 5 ++++ templates/rde/scripts/initProject.sh | 37 +++++++++++++++---------- templates/rde/scripts/initPython.sh | 9 ++++++ templates/rde/scripts/updateDeps.sh | 21 +++++++++++++- 4 files changed, 56 insertions(+), 16 deletions(-) diff --git a/templates/rde/scripts/activateDevenv.sh b/templates/rde/scripts/activateDevenv.sh index e3e4eaa..8b8113a 100644 --- a/templates/rde/scripts/activateDevenv.sh +++ b/templates/rde/scripts/activateDevenv.sh @@ -2,6 +2,11 @@ set -euo pipefail if [[ -f "devenv.nix" ]]; then echo "🚀 Activating devenv environment..." + if ! command -v @defaultPackageName@-devenv &> /dev/null; then + echo "❌ Command '@defaultPackageName@-devenv' not found." + echo "Ensure devenv is properly configured in your environment." + exit 1 + fi exec @defaultPackageName@-devenv shell else echo "❌ No devenv.nix file found in the current directory." diff --git a/templates/rde/scripts/initProject.sh b/templates/rde/scripts/initProject.sh index 09a92d4..ebaf8e8 100644 --- a/templates/rde/scripts/initProject.sh +++ b/templates/rde/scripts/initProject.sh @@ -43,25 +43,32 @@ fi # Initialize git if [[ ! -d ".git" ]]; then - git init - echo "✓ Initialized Git repository" + if ! command -v git &> /dev/null; then + echo "⚠️ Warning: 'git' command not found. Skipping git initialization." + echo "Install git to enable version control." + else + git init + echo "✓ Initialized Git repository" + fi fi # Check if files exist and are not already staged/tracked before adding -if [[ -f "flake.nix" ]] && ! git diff --cached --name-only 2>/dev/null | grep -q "flake.nix" && - ! git ls-files --error-unmatch flake.nix >/dev/null 2>&1; then - echo "✓ Adding flake.nix to Git repository" - git add flake.nix -elif [[ -f "flake.nix" ]]; then - echo "✓ flake.nix already tracked/staged in Git" -fi +if command -v git &> /dev/null && [[ -d ".git" ]]; then + if [[ -f "flake.nix" ]] && ! git diff --cached --name-only 2>/dev/null | grep -q "flake.nix" && + ! git ls-files --error-unmatch flake.nix >/dev/null 2>&1; then + echo "✓ Adding flake.nix to Git repository" + git add flake.nix + elif [[ -f "flake.nix" ]]; then + echo "✓ flake.nix already tracked/staged in Git" + fi -if [[ -f "flake.lock" ]] && ! git diff --cached --name-only 2>/dev/null | grep -q "flake.lock" && - ! git ls-files --error-unmatch flake.lock >/dev/null 2>&1; then - echo "✓ Adding flake.lock to Git repository" - git add flake.lock -elif [[ -f "flake.lock" ]]; then - echo "✓ flake.lock already tracked/staged in Git" + if [[ -f "flake.lock" ]] && ! git diff --cached --name-only 2>/dev/null | grep -q "flake.lock" && + ! git ls-files --error-unmatch flake.lock >/dev/null 2>&1; then + echo "✓ Adding flake.lock to Git repository" + git add flake.lock + elif [[ -f "flake.lock" ]]; then + echo "✓ flake.lock already tracked/staged in Git" + fi fi # Create .gitignore if [[ ! -f ".gitignore" ]]; then diff --git a/templates/rde/scripts/initPython.sh b/templates/rde/scripts/initPython.sh index 7059cde..6c560a5 100644 --- a/templates/rde/scripts/initPython.sh +++ b/templates/rde/scripts/initPython.sh @@ -1,5 +1,14 @@ #!/usr/bin/env bash set -euo pipefail + +# Check if uv command is available +if ! command -v uv &> /dev/null; then + echo "❌ Command 'uv' not found." + echo "UV is required for Python project management." + echo "Ensure UV is properly installed in your environment." + exit 1 +fi + if [[ ! -f "pyproject.toml" ]]; then echo "🐍 Initializing UV project..." uv init diff --git a/templates/rde/scripts/updateDeps.sh b/templates/rde/scripts/updateDeps.sh index 57be44f..c4d6c60 100644 --- a/templates/rde/scripts/updateDeps.sh +++ b/templates/rde/scripts/updateDeps.sh @@ -3,10 +3,29 @@ set -euo pipefail echo "🔄 Updating project dependencies..." +# Check for required commands +if ! command -v wget &> /dev/null; then + echo "❌ Error: 'wget' command not found." + echo "Please install wget to fetch R version information." + exit 1 +fi + +if ! command -v sed &> /dev/null; then + echo "❌ Error: 'sed' command not found." + echo "Please install sed to update flake.nix." + exit 1 +fi + +if ! command -v nix &> /dev/null; then + echo "❌ Error: 'nix' command not found." + echo "Please install Nix to update flake inputs." + exit 1 +fi + # Ensure we're in the repository root if [[ ! -f "flake.nix" ]]; then # Try to find git root - if git rev-parse --show-toplevel >/dev/null 2>&1; then + if command -v git &> /dev/null && git rev-parse --show-toplevel >/dev/null 2>&1; then cd "$(git rev-parse --show-toplevel)" if [[ ! -f "flake.nix" ]]; then echo "❌ Error: flake.nix not found in repository root"