#!/usr/bin/env bash
#
# Restores files removed/changed in the working tree.
# Copyright (c) Petr Baudis, 2005
#
# This script restores given files to their original state.
#
# Without any parameters, it recovers any files removed locally
# whose removal was not recorded by cg-rm.
#
# If passed a set of file names, it restores those files to their
# state as of the last commit (including bringing cg-rm'd files
# back to life; FIXME: does not do that part yet).
#
# This command is complementary to the cg-cancel command, which
# forcefully abandons all the changes in the working tree and
# restores everything to a proper state (including unseeking,
# cancelling merge in progress and rebuilding indexes).

. ${COGITO_LIB}cg-Xlib

ret=0

if [ "$1" ]; then
	while [ "$1" ]; do
		git-checkout-cache "$1" || ret=1
		shift
	done
else
	if [ "$(git-ls-files --deleted)" ]; then
		echo "Recovering files:"
		git-ls-files --deleted | sed "s/^/$(echo -e "\t")/"
	fi
	git-checkout-cache -q -a
fi

git-update-cache --refresh || ret=1

exit $ret
