#!/bin/sh

readonly testroot="test"
rm -rf "$testroot"
mkdir -p "$testroot"

mkdir -p "$testroot/repo"
pushd "$testroot/repo"
# Make a repository.
git init
git commit --allow-empty -m "root commit"

# Create a whitespace error that should be ignored.
echo "* -whitespace" > ".gitattributes"
git add ".gitattributes"

echo "trailing space -> " > "trailing-space"
git add "trailing-space"

git commit -m "trailing space"
readonly revision="$( git rev-parse HEAD )"
popd

echo "Create our 'workarea' setup..."
mkdir -p "$testroot/workarea/worktree"
export GIT_WORK_TREE="$testroot/workarea/worktree"
export GIT_INDEX_FILE="$testroot/workarea/index"
export GIT_DIR="$testroot/repo/.git"

git read-tree -i -m "$revision"
git update-index --refresh --ignore-missing --skip-worktree >/dev/null

# Run diff-tree.
git diff-tree --no-commit-id --root -c --check "$revision"
echo "exit code of diff-tree: $?"
