#!/bin/sh
# Demonstrate that using a ChangeLog in a subdir works from that subdir,
# when using git.  See the diff_outputs_full_file_names method for why
# this is different.  It's easy when run from the top level.

if test "$VERBOSE" = yes; then
  set -x
  vc-dwim --version
fi

. $srcdir/trap-setup

require_git_

framework_failure=0
mkdir -p $tmp || framework_failure=1
cd $tmp || framework_failure=1

mkdir s || framework_failure=1
touch s/f s/ChangeLog || framework_failure=1
git init > /dev/null || framework_failure=1
git add . || framework_failure=1
git commit -m m . > /dev/null || framework_failure=1

if test $framework_failure = 1; then
  echo "$0: failure in testing framework" 1>&2
  (exit 1); exit 1
fi

fail=0

cat <<EOF > s/ChangeLog || fail=1
2006-09-04  Jim Meyering  <jim@meyering.net>

	* f: X.
EOF
echo bow > s/f || fail=1
cd s

vc-dwim ChangeLog > out 2>&1 || fail=1

cat <<\EOF > exp || fail=1
* f: X.
diff --git a/s/f b/s/f
index e69de29..de03f25 100644
--- a/s/f
+++ b/s/f
@@ -0,0 +1 @@
+bow
EOF

cmp out exp || fail=1
test $fail = 1 && diff out exp 2> /dev/null

Exit $fail
