#!/bin/bash # Check if required arguments are provided if [ $# -lt 3 ] || [ $# -gt 4 ]; then echo "Usage: $0 [list_branch]" echo "Example: $0 exclude_list.txt /path/to/git/repo /path/to/output.yaml 'branch1 branch2'" exit 1 fi INPUT_FILE="$1" ROOT_FOLDER="$2" OUTPUT_FILE="$3" LIST_BRANCH="$4" # Check if input file exists if [ ! -f "$INPUT_FILE" ]; then echo "Error: Input file '$INPUT_FILE' not found" exit 1 fi # Check if root folder exists if [ ! -d "$ROOT_FOLDER" ]; then echo "Error: Root folder '$ROOT_FOLDER' not found" exit 1 fi # Check if output YAML file exists, if not create it if [ ! -f "$OUTPUT_FILE" ]; then echo "Output file does not exist. Creating $OUTPUT_FILE" touch "$OUTPUT_FILE" fi # Change to root folder cd "$ROOT_FOLDER" || exit 1 # Initialize output file echo "branches:" > "$OUTPUT_FILE" # Get all git branches git fetch --all if [ -z "$LIST_BRANCH" ]; then branches=$(git branch -r | grep -v HEAD | sed 's/origin\///' | sed 's/^[[:space:]]*//') else branches=$LIST_BRANCH fi # Process each branch for branch in $branches; do echo "Processing branch: $branch" # Checkout branch git checkout "$branch" 2>/dev/null || continue # Get all folders in current branch folders=$(find . -maxdepth 1 -type d -not -path '.' -not -path './.*' | sed 's|./||') # Array to store modules not in input file modules=() # Check each folder against input file while IFS= read -r folder; do # Skip if folder is empty [ -z "$folder" ] && continue # Check if folder is in input file if ! grep -Fxq "$folder" "$INPUT_FILE"; then modules+=("$folder") fi done <<< "$folders" # Write to yaml if there are modules if [ ${#modules[@]} -gt 0 ]; then echo " $branch:" >> "$OUTPUT_FILE" echo " modules:" >> "$OUTPUT_FILE" for module in "${modules[@]}"; do echo " - $module" >> "$OUTPUT_FILE" done fi done echo "Output written to $OUTPUT_FILE"