summaryrefslogtreecommitdiff
path: root/remote.inc.sh
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2014-07-27 12:30:00 -0400
committerDave Reisner <dreisner@archlinux.org>2014-07-30 20:37:23 -0400
commitca642b0dad8c5ee1ec9d172eae534dacd79d9410 (patch)
tree74dd51e2da42a7dfc49dec2ee452de67b6fd3c8a /remote.inc.sh
downloadasp32-ca642b0dad8c5ee1ec9d172eae534dacd79d9410.tar.xz
initial commit
Diffstat (limited to 'remote.inc.sh')
-rw-r--r--remote.inc.sh50
1 files changed, 50 insertions, 0 deletions
diff --git a/remote.inc.sh b/remote.inc.sh
new file mode 100644
index 0000000..b125419
--- /dev/null
+++ b/remote.inc.sh
@@ -0,0 +1,50 @@
+remote_get_all_refs() {
+ local remote=$1
+
+ mapfile -t "$2" < <(git ls-remote "$remote" 'refs/heads/packages/*' |
+ awk '{ sub(/refs\/heads\//, "", $2); print $2 }')
+}
+
+remote_has_package() {
+ local remote=$1 pkgname=$2
+
+ [[ $(git ls-remote "$remote" "$pkgname") ]]
+}
+
+remote_is_tracking() {
+ local repo=$1 pkgname=$2
+
+ git rev-parse "$repo/packages/$pkgname" &>/dev/null
+}
+
+remote_get_tracked_refs() {
+ local remote=$1
+
+ mapfile -t "$2" < <(git branch --remote 2>/dev/null |
+ awk -F'( +|/)' -v "remote=$1" \
+ '$2 == remote && $3 == "packages" { print "packages/" $4 }')
+}
+
+remote_update_refs() {
+ local remote=$1 refspecs=("${@:2}")
+
+ git fetch "$remote" "${refspecs[@]}"
+}
+
+remote_update() {
+ local remote=$1 refspecs
+
+ remote_get_tracked_refs "$remote" refspecs
+
+ # refuse to update everything
+ # TODO: allow this with a flag
+ [[ -z $refspecs ]] && return 0
+
+ remote_update_refs "$remote" "${refspecs[@]}"
+}
+
+remote_get_url() {
+ local remote=$1
+
+ git ls-remote --get-url "$remote"
+}