From fec68ae76ab39a46f3ee63859d614c3eacda4599 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Tue, 14 Jul 2020 01:42:14 +1200 Subject: [PATCH] Automatically update Git remotes to sourcehut --- run.fish | 4 ++++ utils/helpers.fish | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/run.fish b/run.fish index 047aa4d..9110c7e 100755 --- a/run.fish +++ b/run.fish @@ -5,6 +5,8 @@ cd (dirname (status filename)) source utils/helpers.fish; or exit source utils/constants.fish; or exit +update_origin_url 'https://github.com/cloudrac3r/bibliogram-updater(?:.git)?' 'https://git.sr.ht/~cadence/bibliogram-updater'; or exit + if do_update echo 'Self-update successful.' exec ./run.fish @@ -25,6 +27,8 @@ set update_applied false cd bibliogram/src/site +update_origin_url 'https://github.com/cloudrac3r/bibliogram(?:.git)?' 'https://git.sr.ht/~cadence/bibliogram'; or exit + if do_update npm install --no-optional end diff --git a/utils/helpers.fish b/utils/helpers.fish index deccaff..ae349ef 100644 --- a/utils/helpers.fish +++ b/utils/helpers.fish @@ -21,3 +21,18 @@ end function do_update env LANG=C git pull | grep -v 'Already up[ -]to[ -]date.' end + +# Update the URL for the git remote origin in the working directory. +# argv[1]: the previous URL. this must match, or it will not be changed. +# argv[2]: the new URL to change to. +# exit code: non-zero if problems +function update_origin_url + set -l original_url_regex $argv[1] + set -l new_url $argv[2] + set -l current_url (git remote get-url origin) + if string match --regex --entire $original_url_regex $current_url > /dev/null + echo "Changing Git remote URL from $current_url to $new_url" + git remote set-url origin $new_url; or return 1 + git fetch --quiet; or return 1 + end +end -- 2.26.2