#!/usr/bin/env bash
#
# Show status of the GIT repository.
# Copyright (c) Pavel Roskin 2005
# Copyright (c) Petr Baudis 2005
#
# The output includes the list of branches and merge status.
# Current branch is marked by ">".

USAGE="cg-info"

. ${COGITO_LIB}cg-Xlib

mkdir -p $_git/refs/heads
[ "$(find $_git/refs/heads -follow -type f)" ] \
       || die "List of heads is empty."


[ -s "$_git/head-name" ] && echo "Head: $(cat "$_git/head-name")"
[ -s "$_git/branch-name" ] && echo "Branch (informal): $(cat "$_git/branch-name")"

headlink=$(readlink $_git/HEAD)
if [ ! "$headlink" ]; then
	headsha1=$(cat $_git/HEAD)
	echo "Seeked at: $headsha1"
fi

echo "Heads:"

for head in $_git/refs/heads/*; do
	headsha1=$(cat $head)
	headname=$(basename $head)
	if [ "$headname" = "$_git_head" ]; then
		echo "   >$headname $headsha1"
	else
		echo "    $headname $headsha1"
	fi
done

if [ -s "$_git/merging" ]; then
	tmp=$(cat "$_git/merging")
	echo "Merging: $(cat "$_git/merging") ($(cat "$_git/merging-sym"))"
	echo "Merge base: $(cat "$_git/merge-base")"
fi

if [ -s "$_git/blocked" ]; then
	echo "Changes recording BLOCKED:"
	sed 's/^/    /' "$_git/blocked"
fi
