void-packages/common/travis/changed_templates.sh
Đoàn Trần Công Danh 4b009994e5 changed_templates: exit early if no merge-base could be found
GitHub Action and fetch_upstream.sh script limits fetch depth to 200.
With such depth, should the PR was based on very old tree, we couldn't
find the merge-base to diff again.

In theory, we could replace actions/checkout and fetch_upstream.sh to
fetch more than 200 depth. However, there isn't much gain from such
change and it will increase the time to fetch upstream for all PR.
Arguably, such problematic PR couldn't be built because other steps
would build changed packages' dependencies, too.

Let's complain and exit early instead.
2021-06-01 08:31:00 +07:00

31 lines
711 B
Bash
Executable file

#!/bin/sh
#
# changed_templates.sh
if command -v chroot-git >/dev/null 2>&1; then
GIT_CMD=$(command -v chroot-git)
elif command -v git >/dev/null 2>&1; then
GIT_CMD=$(command -v git)
fi
tip="$(git rev-list -1 --parents HEAD)"
case "$tip" in
*" "*" "*) tip="${tip##* }" ;;
*) tip="${tip%% *}" ;;
esac
base="$(git merge-base FETCH_HEAD "$tip")" || {
echo "Your branches is based on too old copy."
echo "Please rebase to newest copy."
exit 1
}
echo "$base $tip" >/tmp/revisions
/bin/echo -e '\x1b[32mChanged packages:\x1b[0m'
$GIT_CMD diff-tree -r --no-renames --name-only --diff-filter=AM \
"$base" "$tip" \
-- 'srcpkgs/*/template' |
cut -d/ -f 2 |
tee /tmp/templates |
sed "s/^/ /" >&2