# set is used to set the environment variables.
#  -e: exit immediately when a command returning a non-zero exit code.
#  -u: treat unset variables as an error.
#  -o pipefail: sets the exit code of a pipeline to that of the rightmost command to exit with a non-zero status,
#       or to zero if all commands of the pipeline exit successfully.
set -euo pipefail

# go mod tidy do not support symlink
cd -P .

GO111MODULE=on go mod tidy

set +e
changes=$(git status -s)
set -e

if [[ "$changes" != "" ]]; then
    # The go mod does't match the source code in the module.
    echo "Your commit is changed after running 'go mod tidy'."
    echo "You must tidy the endless go mod before submitting a PR."
    exit 1
fi
