From 2d3454095b6cbca6112dbdd83e0697752d51d72a Mon Sep 17 00:00:00 2001 From: flu0r1ne Date: Tue, 24 Aug 2021 01:36:10 -0500 Subject: Fetch from non-origin remotes --- git-update-agent | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'git-update-agent') diff --git a/git-update-agent b/git-update-agent index af8a0df..b6126db 100644 --- a/git-update-agent +++ b/git-update-agent @@ -60,12 +60,15 @@ current_version() { } die_no_upstream_found() { + local remote + remote="$1" + die <<_EOF -origin/HEAD is used as the reference for updates -origin/HEAD is not set and UPSTREAM_BRANCH override not provided +$remote/HEAD is used as the reference for updates +$remote/HEAD is not set and UPSTREAM_BRANCH override not provided You can set the upstream branch with: -git remote set-head +git remote set-head $remote _EOF } @@ -250,7 +253,7 @@ update() { remote_branch="$(upstream_branch "$remote")" if [[ -z "$remote_branch" ]]; then - die_no_upstream_found + die_no_upstream_found "$remote" fi local_branch="$(local_branch)" @@ -276,6 +279,12 @@ _EOF fi } +die_init_failure() { + die<<_EOF +A failure occurred while configuring and cloning the repo +_EOF +} + init_repo() { local dir local remote @@ -293,21 +302,27 @@ init_repo() { DEFAULT_BRANCH="main" - trap '{ rm -rf .git; exit 1; }' EXIT + trap '{ rm -rf .git; die_init_failure; }' EXIT set -e git init &>/dev/null git branch -M "$DEFAULT_BRANCH" - git config remote.origin.url "$remote_url" - git config remote.origin.fetch "+refs/heads/*:refs/remotes/$remote/*" + git config "remote.${remote}.url" "$remote_url" + git config "remote.${remote}.fetch" "+refs/heads/*:refs/remotes/$remote/*" set_should_track true - git fetch --force --tags "$remote" &>/dev/null + set +e + + if ! git fetch --force --tags "$remote"; then + die "Could not download content from \"$remote_url\" on \"$DEFAULT_BRANCH\"." + fi + + set -e git remote set-head "$remote" --auto >/dev/null upstream_branch="$(upstream_branch "$remote")" if [[ -z "$upstream_branch" ]]; then - die_no_upstream_found + die_no_upstream_found "$remote" fi remote_ref="$remote/$upstream_branch" @@ -396,4 +411,6 @@ git_update_agent() { update "$dir" } -git_update_agent "$@" +if [[ -z "$NO_EXEC" ]]; then + git_update_agent "$@" +fi -- cgit v1.2.3