summaryrefslogtreecommitdiff
path: root/scripts/convert-git-cache
blob: 33a8edf18fb228ee6c6a5b2182cb0f9abf0139c5 (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
#!/bin/sh
#
# Copyright (C) 2012,2013 Codethink Limited
#
# 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; version 2 of the License.
#
# 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

set -eu

CACHE_ROOT=$(morph --dump-config | grep cachedir | cut -d\  -f3)

REPO_CACHE="${CACHE_ROOT}/gits"

for REPO_DIR in $(cd "${REPO_CACHE}"; ls); do
    cd "${REPO_CACHE}/${REPO_DIR}"
    if test -d .git; then
        echo "Converting ${REPO_DIR}"
        mv .git/* .
        rmdir .git
        git config core.bare true
        git config remote.origin.mirror true
        git config remote.origin.fetch "+refs/*:refs/*"
        echo "Migrating refs, please hold..."
        rm -f refs/remotes/origin/HEAD
        for REF in $(git branch -r); do
            BRANCH=${REF#origin/}
            git update-ref "refs/heads/${BRANCH}" \
                $(git rev-parse "refs/remotes/${REF}")
            git update-ref -d "refs/remotes/${REF}"
        done
        echo "Re-running remote update with --prune"
        if ! git remote update origin --prune; then
            echo "${REPO_DIR} might be broken."
        fi
    else
        echo "Do not need to convert ${REPO_DIR}"
    fi
done