summaryrefslogtreecommitdiff
path: root/bin/git-develacc
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2018-03-31 19:29:41 -0700
committerSean Whitton <spwhitton@spwhitton.name>2018-03-31 19:29:41 -0700
commit60f3a8613f08837984a4a28831089a531fa8505c (patch)
tree89820c20d3691d62481f4ae4e03d149200423780 /bin/git-develacc
parent8fe679e6adc0047838ed0e7f04f348c93dacbaaa (diff)
downloaddotfiles-60f3a8613f08837984a4a28831089a531fa8505c.tar.gz
replace develacc-push and develacc-push-all with git-develacc
Diffstat (limited to 'bin/git-develacc')
-rwxr-xr-xbin/git-develacc70
1 files changed, 70 insertions, 0 deletions
diff --git a/bin/git-develacc b/bin/git-develacc
new file mode 100755
index 00000000..5afbb3b0
--- /dev/null
+++ b/bin/git-develacc
@@ -0,0 +1,70 @@
+#!/bin/bash
+
+# git-develacc -- manage repositories in develacc container
+
+# Copyright (C) 2018 Sean Whitton
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or (at
+# your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+set -e
+
+$HOME/.shenv
+
+# sanity check
+if in-develacc; then
+ echo >&2 "$0: this script should be run outside the develacc container by my normal user"
+ exit 1
+fi
+
+# set variables
+outside_home="$HOME"
+inside_home="$(getent passwd spw | cut -d: -f6)"
+outside="$(pwd)"
+inside="${outside/$outside_home/$inside_home}"
+parent="$(dirname $inside)"
+short="$(basename $outside)"
+
+# clone the repo if needed
+if ! [ -d "$inside" ]; then
+ mkdir -p "$parent"
+ # here we rely on setgid on ~spw
+ git -C "$parent" clone --mirror "$outside" "$short"
+ git -C "$inside" init --bare --shared=group
+ git -C "$inside" unbare
+fi
+
+# sync remotes from outside develacc into develacc
+git remote | while read remote; do
+ if ! [ "$remote" = "develacc" ]; then
+ git -C "$inside" config --local --bool "remote.$remote.skipdefaultupdate" true
+ git -C "$inside" config --local --unset "remote.$remote.url" || true
+ git -C "$inside" config --local --unset "remote.$remote.mirror" || true
+ git -C "$inside" config --local "remote.$remote.fetch" "+refs/heads/*:refs/remotes/$remote/*"
+ fi
+done
+
+# ensure we have a remote for the outside repo
+git -C "$inside" config --local --bool "remote.outside.skipdefaultupdate" true
+git -C "$inside" config --local --unset "remote.outside.url" || true
+git -C "$inside" config --local "remote.outside.fetch" "+refs/heads/*:refs/remotes/outside/*"
+
+# update all remote-tracking refs inside develacc
+git -C "$inside" fetch "$outside" '+refs/remotes/*:refs/remotes/*' '+refs/heads/*:refs/remotes/outside/*'
+
+# update develacc-tracking refs outside develacc
+if ! [ "$(git remote | grep develacc)" ]; then
+ git remote add -f develacc "$inside"
+else
+ git fetch develacc
+fi