curr_branch=$(git branch --show-current)
if [ "$curr_branch" == "main" ]; then
  echo "You are already on main branch."
  exit 1
fi

branch_version=$(cat Cargo.toml | grep version | head -n 1 | cut -d '"' -f 2)

if git checkout main; then
  git pull

  remote_version=$(cat Cargo.toml | grep version | head -n 1 | cut -d '"' -f 2)

  function version_gt() {
    test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"; 
  }
  if version_gt $curr_branch $remote_version; then
    echo "Current version $branch_version is not newer than remote: $remote_version"
    exit 1
  fi
else
  exit 1
fi