#!/bin/bash -e
#============================================================================#
# Find and clone repo from git.alt                                           #
#============================================================================#
# (C) Denis Smirnov <mithraen@freesource.info>          http://mithraen.ru/  #
#============================================================================#

if [ "$1" = "" ]; then
    echo "Use: $0 <package name>" > /dev/stderr
    exit 1
fi
name=$1

type=`girar-get-upload-method "$name" ||:`

if [ "$type" = "srpm" ]; then
    git clone git://git.altlinux.org/srpms/${name:0:1}/${name}.git
else
    girar-clone-build-commit -o girar "$name" "$name"
fi

pushd  "$name" &> /dev/null || exit -1
git --git-dir=".git" config 'remote.origin.url' "git.alt:packages/$name"
git --git-dir=".git" config 'remote.origin.push' "refs/heads/*:refs/heads/*"
git --git-dir=".git" config 'remote.origin.fetch' "+refs/heads/*:refs/remotes/origin/*"
gear-rules-restore-branches
