#!/usr/bin/env bash
set -ev

test $DARCS || DARCS=$PWD/../darcs

DARCS_EMAIL='tester'
export DARCS_EMAIL

# Test the --no-deps option with Send, Push, Pull, Obliterate and Unrecord.
#
# Create four patches with dependencies.
#   file 'f': patch 'fa' and 'fb'
#   file 'g': patch 'ga' and 'gb'
# The 'b' patches depend on the 'a' patches.

rm -rf tmp1
mkdir tmp1
cd tmp1
$DARCS init
echo 'record no-ask-deps' >> _darcs/prefs/defaults
echo 'record ignore-times' >> _darcs/prefs/defaults
echo 'a' > f
$DARCS add f
$DARCS rec -am 'fa' f
echo 'a' > g
$DARCS add g
$DARCS rec -am 'ga' g
echo 'b' > f
$DARCS rec -am 'fb' f
echo 'b' > g
$DARCS rec -am 'gb' g


mkdir d
$DARCS init --repodir d


# Try to Send all 'b' and 'g' patches. The two 'g' patches should succeed,
# but the 'fb' patch depends on the unselected 'fa' patch, an should be
# skipped.

$DARCS send -o bundle -a -p '[bg]' --no-deps d
grep '^\[ga$' bundle
grep '^\[fb$' bundle && exit 1


# Try to Push all 'b' and 'g' patches. Expect same result as for Send.

$DARCS push -a -p '[bg]' --no-deps d
cd d
$DARCS changes | grep '^  \* ga$'
$DARCS changes | grep '^  \* fb$' && exit 1
# stay in d !!


# Try to Pull all 'b' and 'g' patches. Expect same result as for Send.

# already in d
rm -rf *; $DARCS init
$DARCS pull -a -p '[bg]' --no-deps ..
$DARCS changes | grep '^  \* ga$'
$DARCS changes | grep '^  \* fb$' && exit 1
cd ..


# Try to Obliterate all 'a' and 'g' patches. The two 'g' patches should
# succeed, but the 'fa' patch depends on the unselected 'fb' patch, an
# should be skipped.

$DARCS get . tmp; cd tmp
echo y/y/y/q | tr / \\012 | $DARCS obliterate -p '[ag]' --no-deps
$DARCS changes | grep '^  \* gb$' && exit 1
$DARCS changes | grep '^  \* fa$'
cd ..


# Try to Unrecord all 'a' and 'g' patches. Expect same result as for
# Obliterate.

# in "top" tmp repo -- destroys it!
echo y/y/y/q | tr / \\012 | $DARCS unrecord -p '[ag]' --no-deps
$DARCS changes | grep '^  \* gb$' && exit 1
$DARCS changes | grep '^  \* fa$'

cd ..
rm -rf tmp1
