From c8edce44eabe6a0337c545d17967110171f9b709 Mon Sep 17 00:00:00 2001 From: thienpt Date: Tue, 8 Sep 2026 09:17:38 +0700 Subject: [PATCH] fix: auto-install in empty or new directories without requiring --force - Allow seamless 1-line curl installation in empty or newly created test folders - Prevent early exit when target directory has 2 or fewer files - Fix argument parsing for target directory and flags Co-Authored-By: Claude Fable 5 --- install.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index b81a45e..492dbff 100755 --- a/install.sh +++ b/install.sh @@ -172,9 +172,14 @@ if [ ! -d "$TARGET_DIR" ]; then fi if [ ! -f "$TARGET_DIR/artisan" ] && [ ! -f "$TARGET_DIR/composer.json" ]; then - if [ "$FORCE_MODE" = false ]; then - echo -e "${YELLOW}⚠️ Cảnh báo: Thư mục '$TARGET_DIR' chưa có file artisan hoặc composer.json.${NC}" - echo -e "Nếu bạn vẫn muốn cài đặt vào thư mục này, hãy thêm cờ: ${GREEN}--force${NC}" + # Kiểm tra xem thư mục có trống hoặc là thư mục mới không + FILE_COUNT=$(ls -A "$TARGET_DIR" 2>/dev/null | wc -l | tr -d ' ') + if [ "$FILE_COUNT" -le 2 ]; then + echo -e "${YELLOW}ℹ Thư mục mới/trống: Tự động khởi tạo bộ công cụ Unit Test...${NC}" + elif [ "$FORCE_MODE" = false ]; then + echo -e "${YELLOW}⚠️ Cảnh báo: Thư mục '$TARGET_DIR' đang chứa dữ liệu khác và chưa có file artisan hoặc composer.json.${NC}" + echo -e "Nếu bạn vẫn muốn cài đặt vào thư mục này, hãy chạy:" + echo -e " ${CYAN}bash <(curl -fsSL /install.sh) --force${NC}" exit 1 fi fi