#!/usr/bin/env bash
#
# Pulls changes from another branch to the local repository and merge changes.
# Copyright (c) Petr Baudis, 2005
#
# Takes the branch' name; no parameter will cause it to update
# against HEAD (only recovers lost files for now).

. cg-Xlib

name=$1

if [ ! "$name" ]; then
	# Update working tree against HEAD. Fair enough. We just
	# reintroduce the missing files for now.
	if [ "$(show-files --deleted)" ]; then
		echo "Recovering files:"
		show-files --deleted | sed "s/^/$(echo -e "\t")/"
		show-files -z --deleted | xargs -0 checkout-cache --
	fi
	exit
fi

cg-pull $name || exit 1
echo
echo "Applying changes..."
cg-merge $name
