stages:
  - update

update_subtree:
  stage: update
  script:
    - echo "Configuring Git user..."
    - git config --global user.email "bot@csspageweaver.org"
    - git config --global user.name "Update Bot"

    - echo "Updating subtree..."
    - git subtree pull --prefix=csspageweaver https://gitlab.com/csspageweaver/csspageweaver.git main --squash
    
    # Fetch the latest changes from the remote to compare
    - git fetch origin

    # Check if there are any changes to push
    - |
      if git diff --quiet origin/main; then
        echo "No changes to push."
      else
        echo "Pushing changes..."
        git push https://oauth2:${ACCESS_TOKEN}@gitlab.com/csspageweaver/boilerplate.git HEAD:main
      fi

  only:
    - schedules
    - triggered
