#!/usr/bin/env bash

# Usage (execute in root of project):
#     bin/update-standard v2.5.2

set -e

if [ -d "moodle" ]; then
    rm -rf moodle
fi

if [ -d "PHPCompatibility" ]; then
    rm -rf PHPCompatibility
fi

if [ -d "moodle-local_codechecker" ]; then
    rm -rf moodle-local_codechecker
fi

git clone --branch $1 https://github.com/moodlehq/moodle-local_codechecker.git

cp -R moodle-local_codechecker/moodle moodle
cp -R moodle-local_codechecker/PHPCompatibility PHPCompatibility

# Tests can only be ran in Moodle, no need to keep them.
rm -rf moodle/tests

git add -A moodle
git add -A PHPCompatibility

# Cleanup.
if [ -d "moodle-local_codechecker" ]; then
    rm -rf moodle-local_codechecker
fi

echo "The 'moodle' and 'PHPCompatibility' directories are ready to be reviewed and committed";
