# @TEST-EXEC: zkg install foo

# @TEST-EXEC: bash %INPUT
# @TEST-EXEC: zkg refresh
# @TEST-EXEC: zkg list outdated > outdated.out
# @TEST-EXEC: btest-diff outdated.out

# @TEST-EXEC: zkg list all > list.out
# @TEST-EXEC: btest-diff list.out

# With --fail-on-aggregate problems, the following should fail since
# there are metadata problems in the package set.
# @TEST-EXEC-FAIL: zkg -vvv refresh --aggregate --fail-on-aggregate-problems >agg.fail.out 2>agg.fail.errout.orig
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff agg.fail.out
# @TEST-EXEC: grep -v 'built-in package' < agg.fail.errout.orig > agg.fail.errout
# @TEST-EXEC: TEST_DIFF_CANONIFIER='$SCRIPTS/diff-canonifier' btest-diff agg.fail.errout

# Remove the aggregated metadata so the next invocation has a clean slate
# @TEST-EXEC: rm -f state/clones/source/one/aggregate.meta

# This time we trigger only warnings for offending packages, commit, and push.
# @TEST-EXEC: zkg -vvv refresh --aggregate --push >agg.out 2>agg.errout.orig
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff agg.out
# @TEST-EXEC: grep -v 'built-in package' < agg.errout.orig > agg.errout
# @TEST-EXEC: TEST_DIFF_CANONIFIER='$SCRIPTS/diff-canonifier' btest-diff agg.fail.errout
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-canonifier btest-diff agg.errout

# @TEST-EXEC: zkg search lucky > search.out
# @TEST-EXEC: btest-diff search.out

# @TEST-EXEC: zkg list all > list_after_agg.out
# @TEST-EXEC: btest-diff list_after_agg.out
# note: foo's description isn't in the list output since the installed
# version's metadata has no 'description' field

cd packages/foo
echo 'tags = esoteric lucky land' >> zkg.meta
echo 'description = This is the foo package description' >> zkg.meta
git commit -am 'new stuff'

cd ..
mkdir new_pkg
cd new_pkg
git init
echo '[package]' > zkg.meta
echo 'tags = esoteric lucky land' >> zkg.meta
echo 'description = This is the new_pkg package description' >> zkg.meta
echo 'print "hello";' >> __load__.zeek
git add *
git commit -m 'init'

cd ..
mkdir bad_pkg
cd bad_pkg
git init
echo '[package]' > bad.meta
git add *
git commit -m 'init'

cd ../..
echo "$(pwd)/packages/new_pkg" >> sources/one/alice/zkg.index
echo "$(pwd)/packages/bad_pkg" >> sources/one/alice/zkg.index
cd sources

( cd one && git commit -am 'add packages' )

# Make it a bare repo so we can push to it
mv one one.tmp
git clone --bare one.tmp one
rm -rf one.tmp
