79576846

Date: 2025-04-16 09:42:09
Score: 0.5
Natty:
Report link
detect_new_folders:
  stage: detect
  script:
    - git fetch --unshallow || true
    - git fetch origin
    - echo "Detecting newly added directories in the current commit..."
    - |
      PREV_COMMIT=$(git rev-parse HEAD~1)
      CURR_COMMIT=$(git rev-parse HEAD)
      echo "Previous commit: $PREV_COMMIT"
      echo "Current commit: $CURR_COMMIT"

      # Get added files only
      ADDED_FILES=$(git diff --diff-filter=A --name-only "$PREV_COMMIT" "$CURR_COMMIT")
      echo "Added files:"
      echo "$ADDED_FILES"

      # Extract top-level directories from the added files
      NEW_DIRS=$(echo "$ADDED_FILES" | awk -F/ '{print $1}' | sort -u)

      if [ -z "$NEW_DIRS" ]; then
        echo "no new folders" > new_folders.txt
        echo "No new folders found."
      else
        echo "$NEW_DIRS" > new_folders.txt
        echo "New folders detected:"
        cat new_folders.txt
      fi
  artifacts:
    paths:
      - new_folders.txt
    expire_in: 1 hour
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Vanessa