common-updater-scripts/u-s-v: allow omitting version with --ignore-same-version

This is useful when wanting to update secondary hashes like `cargoDeps`.
This commit is contained in:
Jan Tojnar 2024-06-09 19:47:27 +02:00
parent bcb2f57f18
commit 4627e4849e

View File

@ -13,6 +13,8 @@ usage() {
echo " [--version-key=<version-key>] [--source-key=<source-key>]" echo " [--version-key=<version-key>] [--source-key=<source-key>]"
echo " [--system=<system>] [--file=<file-to-update>] [--rev=<revision>]" echo " [--system=<system>] [--file=<file-to-update>] [--rev=<revision>]"
echo " [--ignore-same-hash] [--ignore-same-version] [--print-changes]" echo " [--ignore-same-hash] [--ignore-same-version] [--print-changes]"
echo ""
echo "The <version> positional argument is also optional when passing --ignore-same-version."
} }
ignoreSameVersion= ignoreSameVersion=
@ -71,7 +73,13 @@ newUrl=${args[3]}
# Third-party repositories might not accept arguments in their default.nix. # Third-party repositories might not accept arguments in their default.nix.
importTree="(let tree = import ./.; in if builtins.isFunction tree then tree {} else tree)" importTree="(let tree = import ./.; in if builtins.isFunction tree then tree {} else tree)"
if (( "${#args[*]}" < 2 )); then if [[ -z "$ignoreSameVersion" ]]; then
requiredArgs=2
else
requiredArgs=1
fi
if (( "${#args[*]}" < $requiredArgs )); then
echo "$scriptName: Too few arguments" echo "$scriptName: Too few arguments"
usage usage
exit 1 exit 1
@ -143,6 +151,10 @@ if [[ -z "$oldVersion" ]]; then
die "Couldn't find out the old version of '$attr'!" die "Couldn't find out the old version of '$attr'!"
fi fi
if [[ -n "$ignoreSameVersion" && -z "$newVersion" ]]; then
newVersion="$oldVersion"
fi
if [[ -z "$ignoreSameVersion" && "$oldVersion" = "$newVersion" ]]; then if [[ -z "$ignoreSameVersion" && "$oldVersion" = "$newVersion" ]]; then
echo "$scriptName: New version same as old version, nothing to do." >&2 echo "$scriptName: New version same as old version, nothing to do." >&2
if [ -n "$printChanges" ]; then if [ -n "$printChanges" ]; then