#!/usr/bin/env bash
#
# Common code shared by the Cogito toolkit.
# Copyright (c) Petr Baudis, 2005
#
# This file provides a library containing common code shared with all the
# Cogito programs.

_cg_cmd=${0##*/}

die () {
	echo $_cg_cmd: $@ >&2
	exit 1
}


# Compatibility hacks:
# 2005-04-26
if [ -d .git ] && [ -s .git/remotes ] && [ ! -e .git/branches ]; then
	stop=
	mkdir .git/branches || stop=1
	[ "$stop" ] || cat .git/remotes | while read branch location; do
		echo "$location" >.git/branches/$branch
	done || stop=1
	[ "$stop" ] || rm .git/remotes
fi
# 2005-04-26
if [ -d .git ] && [ ! -d .git/refs ]; then
	stop=
	mkdir .git/refs || stop=1
	if [ ! "$stop" ]; then
		mv .git/heads .git/refs
		mv .git/tags .git/refs
		tgt=$(readlink .git/HEAD)
		if [ "$tgt" ]; then
			rm .git/HEAD
			ln -s "refs/$tgt" .git/HEAD
		fi
	fi
fi
