#! /bin/sh
. "${0%/*}/test.subr"

set_up_package "git-update.mk"
set_up_repository git

step "Testing Git before an update in the remote repository"
package_make patch

assert_that --file "$wrkdir/pkgbase/today" --has-content "2018-03-01"


# A newer version becomes available in the remote repository.  Since the
# package uses the default reference origin/HEAD, it will pick up these
# changes.
cd "$repoworkdir"
scm_git_commit "2022-03-01"

step "Testing Git after an update in the remote repository"
package_make clean
package_make patch
# The output contains "Creating cached Git archive".

assert_that --file "$wrkdir/pkgbase/today" --has-content "2022-03-01"

# Ensure that the archive in ${DISTDIR} has been updated, to avoid
# unnecessary downloads in the future.
cd "$wrkdir"
echo "before-tar" > pkgbase/today
tar xfz "$distdir/git-packages/pkgbase-default-gitarchive.tar.gz" pkgbase/today
assert_that --file "pkgbase/today" --has-content "2022-03-01"


step "Testing Git from a cached archive that has been updated"
package_make clean
package_make patch
# The output does not contain "Creating cached Git archive" since origin/HEAD
# still points to the same commit as before.

assert_that --file "$wrkdir/pkgbase/today" --has-content "2022-03-01"
