#!/bin/bash

if [ "$#" -ne 1 ]
then
  echo "Usage: create-tag.sh 1.2.3"
  exit 1
fi

if [ ! -d "trunk" ]; then
  echo "Change to the directory containing trunk"
  exit 1
fi

echo "Creating tag $1"
echo ""

# Create tag directory if it doesn't exist
if [ ! -d "tags" ]; then
  svn mkdir tags
fi

# Copy trunk to tag using SVN (this respects svn:ignore properties)
svn cp trunk tags/$1

# Clean up any ignored files that might have been copied
echo "Cleaning ignored files from tag..."
cd tags/$1

# Remove files that match svn:ignore patterns
for ignored_file in .idea asadebug.txt .wp-env.json tmp one-theme GEMINI.md .security-reports .claude CLAUDE.md; do
  if [ -e "$ignored_file" ]; then
    echo "Removing ignored file/directory: $ignored_file"
    svn delete "$ignored_file" --force 2>/dev/null || rm -rf "$ignored_file"
  fi
done

cd ../..

# Commit tag
svn ci -m "tag version $1" tags/$1

# Add any new files in trunk that should be versioned
echo "Adding new files to trunk..."
cd trunk
# Only add files that are not ignored
svn add * --parents --auto-props --parents 2>/dev/null || true
cd ..

# Commit trunk
svn ci -m "release version $1" trunk
