Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Rishat Sultanov
cbmroot_geometry
Commits
fcebecb7
Commit
fcebecb7
authored
Oct 23, 2020
by
Pierre-Alain Loizeau
Browse files
Add CI with branch status checks against upstream master branch
parent
117489d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
0 → 100644
View file @
fcebecb7
stages
:
-
checkRepository
RebaseCheck
:
stage
:
checkRepository
tags
:
-
CbmRoot
only
:
refs
:
-
merge_requests
variables
:
-
$CI_MERGE_REQUEST_PROJECT_PATH == "CbmSoft/cbmroot_geometry" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"
script
:
# Get the upstream repository manually. I did not find any other way to have it for
# comparison
# Check if a rebase is needed
# If a rebase is needed stop immediately
-
scripts/connect_upstream_repo.sh $CI_MERGE_REQUEST_PROJECT_URL
-
git fetch upstream
-
hash1=$(git show-ref upstream/master | cut -f1 -d' ')
-
hash2=$(git merge-base upstream/master origin/$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME)
-
echo "${hash1}"
-
echo "${hash2}"
-
if [ "${hash1}" = "${hash2}" ]; then
-
echo "No rebase required"
-
exit
0
-
else
-
echo "The Merge Request is not up-to-date"
-
echo "Rebase is required"
-
exit
1
-
fi
LinearHistCheck
:
stage
:
checkRepository
tags
:
-
CbmRoot
only
:
refs
:
-
merge_requests
variables
:
-
$CI_MERGE_REQUEST_PROJECT_PATH == "CbmSoft/cbmroot_geometry" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"
script
:
# Get the upstream repository manually. I did not find any other way to have it for
# comparison
# Check if the history introduced by the MR is linear (no branch loop in fork)
# If not linear stop immediately
-
scripts/connect_upstream_repo.sh $CI_MERGE_REQUEST_PROJECT_URL
-
git fetch upstream
-
count=$(git rev-list --min-parents=2 --count upstream/master..HEAD)
-
echo "${count}"
-
if [ 0 = "${count}" ]; then
-
echo "History introduced in fork is linear"
-
exit
0
-
else
-
echo "History introduced in fork is not linear"
-
echo "${count} merge commits must be removed or the other new commits have to be replayed in a new branch"
-
exit
1
-
fi
ci_scripts/connect_upstream_repo.sh
0 → 100644
View file @
fcebecb7
#!/bin/bash
upstream_repo
=
$1
bla
=
$(
git remote
-v
|
grep
upstream
)
if
[
$?
-eq
0
]
;
then
echo
"Remote link upstream already exist"
bla
=
$(
git remote
-v
|
grep
upstream |
grep
$upstream_repo
)
if
[
$?
-eq
0
]
;
then
echo
"Remote link upstream already exist and points to the correct repo"
# dont do anything
else
echo
"Remote link upstream already exist and points to the wrong repo"
git remote
rm
upstream
git remote add upstream
$upstream_repo
fi
else
echo
"Remote repo has to be connected"
git remote add upstream
$upstream_repo
fi
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment