source ./scripts/include/vars.sh
source ./scripts/include/sudo.sh

# If directory release doesn't exist, initialize the git repo
if [ ! -d $RELEASE_GIT_DIR ]; then
  mkdir $RELEASE_GIT_DIR
  cd $RELEASE_GIT_DIR
  git init
fi

# Go to the root directory
cd $ROOT_DIR

# Check if the releases directory exists
if [ ! -d $RELEASES_DIR ]; then
  echo "No releases directory found. Exiting..."
  exit 1
fi

# Iterate over all directories in the releases directory
for release_dir in $(ls $RELEASES_DIR); do
  release_dir="$RELEASES_DIR/$release_dir"

  echo "got release_dir: $release_dir"

  sudo rm -rf $RELEASE_GIT_DIR/*
  cd $RELEASE_GIT_DIR
  
  echo "copying everything from $release_dir to $RELEASE_GIT_DIR ..."
  sudo cp -r $release_dir/* $RELEASE_GIT_DIR

  git add .
  git commit -m "release: update version $release_dir"

  cd $ROOT_DIR
done