#!/usr/bin/env bash # git-develacc -- manage repositories in develacc NFS share # 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 # sanity check if [ "$(hostname)" = 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)" inside_home="/home/spwhitton/local/develacc" 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" ] && ! [ "$remote" = "dgit" ]; then # this is to disable `git remote update` and therefore my `mr update` git -C "$inside" config --local --bool "remote.$remote.skipdefaultupdate" true # we need a url on the origin remote so that `mr register` # works. And then we might as well set an url on all the # remotes (except 'outside') for a nicer display in magit. url="$(git config --local remote.$remote.url)" git -C "$inside" config --local "remote.$remote.url" "$url" 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 "remote.outside.url" "$outside" # magit cosmetics git -C "$inside" config --local "remote.outside.fetch" "+refs/heads/*:refs/remotes/outside/*" # update all remote-tracking refs inside develacc git -C "$inside" fetch --prune --tags "$outside" \ '+refs/remotes/*:refs/remotes/*' \ '+refs/heads/*:refs/remotes/outside/*' git -C "$inside" update-ref -d 'refs/remotes/develacc/*' # prune old remotes git -C "$inside" remote | while read remote; do if ! [ "$remote" = "origin" ] && ! [ "$remote" = "outside" ]; then if ! git remote | grep --quiet "$remote"; then git -C "$inside" remote rm "$remote" fi fi done # update develacc-tracking refs outside develacc if ! [ "$(git remote | grep develacc)" ]; then git remote add -f develacc "$inside" else git fetch develacc fi