#!/usr/bin/env bash

# A partial get of a repo shall have the same _darcs/pristine as the original

set -ev
test $DARCS || DARCS=$PWD/../darcs

rm -rf temp
mkdir temp
cd temp

# Create a development repo, do some work

$DARCS initialize --darcs-2
echo ALL ignore-times >> _darcs/prefs/defaults
touch a
$DARCS add a
$DARCS record -a -m aa -A x
touch b
$DARCS add b
$DARCS record -a -m bb -A x

# Create a release repo, pull the good patches and tag it

mkdir _rel
cd _rel
$DARCS initialize --darcs-2 
$DARCS pull -a --patch a ..
$DARCS tag -m tt -A x
cd ..

# Pull the tag to the devel repo and continue developement

$DARCS pull -a _rel
touch c
$DARCS add c
$DARCS record -a -m cc -A x

# Create a checkpoint and get a partial temp repo

$DARCS tag -A x --checkpoint first_checkpoint 
$DARCS get --partial . _partial

# We should have all our devel files

cd _partial
cat a
cat b
cat c

# This is a regression test for issue406
$DARCS tag -A x --checkpoint checkpointing_a_partial

cd ..

# With the darcs-2 format, doing a get on a partial repo succeeds.
# With the darcs-1 format it would be required to add the --partial flag, or darcs would give an error. 
$DARCS get _partial _second_partial

cd ..
rm -rf temp
