summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorflu0r1ne <flu0r1ne@flu0r1ne.net>2021-08-24 01:36:10 -0500
committerflu0r1ne <flu0r1ne@flu0r1ne.net>2021-08-24 01:36:10 -0500
commit2d3454095b6cbca6112dbdd83e0697752d51d72a (patch)
treed84a9e3ee2212bf52704a07ef99950b9b94aa189
parente504ed5981dd2df69865ede16722c2e1632de774 (diff)
downloadgit-update-agent-2d3454095b6cbca6112dbdd83e0697752d51d72a.tar.xz
git-update-agent-2d3454095b6cbca6112dbdd83e0697752d51d72a.zip
Fetch from non-origin remotes
-rw-r--r--git-update-agent37
1 files changed, 27 insertions, 10 deletions
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 <name> <branch>
+git remote set-head $remote <branch>
_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