set -e
set -u

# just a sanity check that we're actually using the one I compiled from git
rsync --version

top_dir=rsync_test
send_dir="${top_dir}/send"
recv_dir="${top_dir}/recv"
files_from="${top_dir}/files"

rm -rf "${top_dir}"
mkdir -p "${send_dir}"
mkdir -p "${recv_dir}"

# populate
mkdir -p "${send_dir}/dir"
echo "plain file 1" > "${send_dir}/file1"
echo "plain file 2" > "${send_dir}/dir/file2"

# build manual file list
echo "file1" >> "${files_from}"
echo "dir/file2" >> "${files_from}"

# --exclude=file1 excludes file1 as expected
#rsync -avz --files-from="${files_from}" --exclude=file1 "${send_dir}/" "${recv_dir}/"

# --exclude=dir doesn't actually exclude dir :-/
rsync -avz --files-from="${files_from}" --exclude=dir "${send_dir}/" "${recv_dir}/"

# --exclude=dir does exclude it if we don't use --files-from=
#rsync -avz --exclude=dir "${send_dir}/" "${recv_dir}/"

# workaround: --exclude=dir/** _does_ exclude dir
#rsync -avz --files-from="${files_from}" --exclude='dir/**' "${send_dir}/" "${recv_dir}/"

find "${send_dir}" "${recv_dir}"
