blob: 85f370d7013dfae72d8a5b97417c13883f08cd50 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#!/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 <https://www.gnu.org/licenses/>.
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
|