summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2020-12-03 16:23:54 -0800
committerPhilip Chimento <philip.chimento@gmail.com>2021-01-02 12:23:52 -0800
commitdeb8fbe62ce5b5a91a7d890c6d9c11263cf34d97 (patch)
treea7e63efd0517df482ae45dd94208f9fbe40593e5 /test
parent2593b3a262d184f97a5ac270c927bed8fb115972 (diff)
downloadgjs-deb8fbe62ce5b5a91a7d890c6d9c11263cf34d97.tar.gz
CI: Fix getting the upstream base
Use git-merge-base to calculate the newest common ancestor, which should be more reliable. Also increase the horizon to 28 days since the newest common ancestor of this very merge request is more than 14 days old. Check that any commits were fetched (if not, "the remote end hung up unexpectedly") and fetch the last 30 commits instead if it didn't work. (Code review suggestion from Evan) As well, it seems that this feature does not always work quite correctly, so it would be good to have some debug output.
Diffstat (limited to 'test')
-rwxr-xr-xtest/test-ci.sh15
1 files changed, 11 insertions, 4 deletions
diff --git a/test/test-ci.sh b/test/test-ci.sh
index f3e780a0..830d0faf 100755
--- a/test/test-ci.sh
+++ b/test/test-ci.sh
@@ -35,7 +35,12 @@ do_Get_Upstream_Base () {
git remote add upstream https://gitlab.gnome.org/GNOME/gjs.git || \
git remote set-url upstream https://gitlab.gnome.org/GNOME/gjs.git
base_branch="${CI_MERGE_REQUEST_TARGET_BRANCH_NAME:-${CI_DEFAULT_BRANCH}}"
- git fetch --shallow-since="14 days ago" --no-tags upstream "$base_branch"
+ if ! git fetch --shallow-since="28 days ago" --no-tags upstream "$base_branch"; then
+ echo "Main branch doesn't have history in the past 28 days, fetching "
+ echo "the last 30 commits."
+ git fetch --depth=30 --no-tags upstream "$base_branch"
+ fi
+
git branch ci-upstream-base-branch FETCH_HEAD
# Work out the newest common ancestor between the detached HEAD that this CI
@@ -44,13 +49,15 @@ do_Get_Upstream_Base () {
#
# $CI_MERGE_REQUEST_TARGET_BRANCH_NAME is only defined if we’re running in a
# merge request pipeline; fall back to $CI_DEFAULT_BRANCH otherwise.
- git rev-list --first-parent ci-upstream-base-branch | tac > base-revs.txt
- git rev-list --first-parent HEAD | tac > head-revs.txt
- newest_common_ancestor_sha=$(comm -12 base-revs.txt head-revs.txt | tail -1)
+ newest_common_ancestor_sha=$(git merge-base ci-upstream-base-branch HEAD)
if test -z "$newest_common_ancestor_sha"; then
echo "Couldn’t find common ancestor with the upstream main branch. This"
echo "typically happens if you branched a long time ago. Please update"
echo "your clone, rebase, and re-push your branch."
+ echo "Base revisions:"
+ git log --oneline -10 ci-upstream-base-branch
+ echo "Branch revisions:"
+ git log --oneline -10 HEAD
exit 1
fi
echo "Merge base:"