summaryrefslogtreecommitdiff
path: root/bin/git-develacc
blob: e1d52f80b3746e68b0bcccdfcde1b25086319a11 (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
#!/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 --prune --tags "$outside" \
    '+refs/remotes/*:refs/remotes/*' \
    '+refs/heads/*:refs/remotes/outside/*'
git -C "$inside" update-ref -d 'refs/remotes/develacc/*'

# update develacc-tracking refs outside develacc
if ! [ "$(git remote | grep develacc)" ]; then
    git remote add -f develacc "$inside"
else
    git fetch develacc
fi