#!/bin/bash
#
# Update Cargo.lock.
#
# Run manually as needed.
#
# Any arguments are passed through to "cargo update".

set -euo pipefail

# CARGO=nailing-cargo maint/update-dependencies

# We need to piss abouthere because we can otherwise pick up versions
# which are incompatible with our pinned nightly.
# https://github.com/rust-lang/cargo/issues/16672

msrv=$(perl -ne 'print $1 if m/^rust-version = \"([0-9.]+)\"\s*/' Cargo.toml)
pinned=$(${CARGO-cargo} version | perl -pe 's/^\w+ //; s/-nightly.*//')

tomls=$(git-ls-files | grep Cargo.toml)
perl -i~ -pe 's/\b\Q'"$msrv"'\E\b/'"$pinned"'/ if m/^rust-version/' $tomls

${CARGO-cargo} +1.93 update						   \
	       --config 'resolver.incompatible-rust-versions = "fallback"' \
	       "$@"

git checkout HEAD $tomls
