From 6bdca276a2318fa1fd2f9f9df7a475c52bb44a33 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Sun, 28 Jun 2020 14:01:19 +0100 Subject: [PATCH] ci: Create new origin for forks We don't need to create a new remote and fetch its master if we're checking a merge request done on the upstream repository. --- .gitlab-ci/run-style-check-diff.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci/run-style-check-diff.sh b/.gitlab-ci/run-style-check-diff.sh index 35a1bb4a39..42ef5d9fee 100755 --- a/.gitlab-ci/run-style-check-diff.sh +++ b/.gitlab-ci/run-style-check-diff.sh @@ -4,8 +4,15 @@ set -e # We need to add a new remote for the upstream master, since this script could # be running in a personal fork of the repository which has out of date branches. -git remote add upstream https://gitlab.gnome.org/GNOME/gtk.git -git fetch upstream +if [ "${CI_PROJECT_NAMESPACE}" != "GNOME" ]; then + echo "Retrieving the current upstream repository from ${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}..." + git remote add upstream https://gitlab.gnome.org/GNOME/gtk.git + git fetch upstream + ORIGIN="upstream" +else + echo "Reusing the existing repository on ${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}" + ORIGIN="origin" +fi # Work out the newest common ancestor between the detached HEAD that this CI job # has checked out, and the upstream target branch (which will typically be @@ -13,7 +20,7 @@ git fetch upstream # # `${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. -newest_common_ancestor_sha=$(diff --old-line-format='' --new-line-format='' <(git rev-list --first-parent "upstream/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME:-${CI_DEFAULT_BRANCH}}") <(git rev-list --first-parent HEAD) | head -1) +newest_common_ancestor_sha=$(diff --old-line-format='' --new-line-format='' <(git rev-list --first-parent "${ORIGIN}/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME:-${CI_DEFAULT_BRANCH}}") <(git rev-list --first-parent HEAD) | head -1) git diff -U0 --no-color "${newest_common_ancestor_sha}" | .gitlab-ci/clang-format-diff.py -binary "clang-format" -p1 exit_status=$?