#!/bin/sh

mkdir privacy_lost
cd privacy_lost

fossil new origin.fossil
fossil open origin.fossil

echo "Initial file" > readme.txt
fossil add readme.txt
fossil ci -f -m "Initial non-private checkin"

sleep 1

echo "Private file" > private.txt
fossil add private.txt
fossil ci -f -m "First private checkin" --private

fossil close
rm readme.txt private.txt

fossil clone origin.fossil origin_clone.fossil

fossil open origin_clone.fossil

[ ! -e readme.txt ] && echo "OUCH: where is readme.txt gone?"
[ -e private.txt ] && echo "OUCH: why is private.txt within clone?"

fossil close
rm readme.txt private.txt

mkdir deconstructed
fossil deconstruct -R origin.fossil deconstructed
fossil reconstruct recon.fossil deconstructed

[ -d deconstructed ] && rm -rf deconstructed
[ ! -e recon.fossil ] && echo "OUCH: Where is my reconstructed repository?"

fossil open recon.fossil

[ ! -e readme.txt ] && echo "OUCH: where is readme.txt gone?"
[ ! -e private.txt ] && echo "OUCH: where is private.txt gone?"

fossil close
rm readme.txt private.txt

fossil clone recon.fossil recon_clone.fossil

fossil open recon_clone.fossil

[ ! -e readme.txt ] && echo "OUCH: where is readme.txt gone?"
[ -e private.txt ] && echo "OUCH: why is private.txt within clone?"

fossil close
rm readme.txt private.txt

rm origin.fossil origin_clone.fossil recon.fossil recon_clone.fossil

cd ..
rmdir privacy_lost

exit 0
