From 60f3a8613f08837984a4a28831089a531fa8505c Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 31 Mar 2018 19:29:41 -0700 Subject: replace develacc-push and develacc-push-all with git-develacc --- bin/git-develacc | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 bin/git-develacc (limited to 'bin/git-develacc') 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 . + +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 -- cgit v1.2.3