summaryrefslogtreecommitdiff
path: root/scripts/convert-git-cache
diff options
context:
space:
mode:
authorDaniel Silverstone <daniel.silverstone@codethink.co.uk>2012-09-14 09:34:32 +0100
committerDaniel Silverstone <daniel.silverstone@codethink.co.uk>2012-09-14 17:25:29 +0100
commitf276815a6468a10da9ea381b58b92e32450cf7ab (patch)
tree4976637f8cf19967e62d1cadfa93d4c0ea24acb8 /scripts/convert-git-cache
parent38e226e48b498b0adfb9c8559e592ed16ed8ac56 (diff)
downloadmorph-f276815a6468a10da9ea381b58b92e32450cf7ab.tar.gz
Script for converting git cache.
This script converts a git cache from the current format to the new bare format. It need only stay around for a while (perhaps until after the next Baserock release) and then it can be removed.
Diffstat (limited to 'scripts/convert-git-cache')
-rwxr-xr-xscripts/convert-git-cache51
1 files changed, 51 insertions, 0 deletions
diff --git a/scripts/convert-git-cache b/scripts/convert-git-cache
new file mode 100755
index 00000000..95ed83c8
--- /dev/null
+++ b/scripts/convert-git-cache
@@ -0,0 +1,51 @@
+#!/bin/sh
+#
+# Copyright (C) 2012 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.
+
+# This is a program to convert the json dump of the overlaps between artifacts
+# in a format more suited to shell programs, or human reading
+
+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