fec68ae76ab39a46f3ee63859d614c3eacda4599 — Cadence Ember 11 months ago 86226e7
Automatically update Git remotes to sourcehut
2 files changed, 19 insertions(+), 0 deletions(-)

M run.fish
M utils/helpers.fish
M run.fish => run.fish +4 -0
@@ 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

M utils/helpers.fish => utils/helpers.fish +15 -0
@@ 21,3 21,18 @@ end
function do_update
	env LANG=C git pull | grep -v 'Already up[ -]to[ -]date.'

# 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