From: Kefu Chai Date: Mon, 20 Dec 2021 12:59:46 +0000 (+0800) Subject: ceph-pr-submodules: extract the check into a function X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=ad1ed75755a92e6718525a470425556670bbe929;p=ceph-build.git ceph-pr-submodules: extract the check into a function prepare for the next commit which add an escape rule Signed-off-by: Kefu Chai --- diff --git a/ceph-pr-submodules/build/build b/ceph-pr-submodules/build/build index 747bc73d..339dcb18 100644 --- a/ceph-pr-submodules/build/build +++ b/ceph-pr-submodules/build/build @@ -4,21 +4,28 @@ set -ex cd "$WORKSPACE" -# Ensure that our clone has the very latest target branch. -# The Jenkins Git plugin may have not updated this particular ref. -git fetch origin ${ghprbTargetBranch}:refs/remotes/origin/${ghprbTargetBranch} +function has_modified_submodules() { + local target_branch=$1 + shift + local actual_commit=$1 + shift + # Ensure that our clone has the very latest target branch. + # The Jenkins Git plugin may have not updated this particular ref. + git fetch origin ${target_branch}:refs/remotes/origin/${target_branch} -echo "Comparing the following target branch:" -git rev-parse origin/${ghprbTargetBranch} + echo "Comparing the following target branch:" + git rev-parse origin/${target_branch} -# show diffs between $ghprbTargetBranch (where the merge is going) and -# $ghprbActualCommit (the tip of the branch that's merging) with '...', -# which is equivalent to diff $(git merge-base TB AC) AC, or "show -# diff from common ancestor of the target branch and this branch with the -# tip of this branch". With --submodule, also show detail of diff in submodules. -modified_submodules="$(git diff --submodule=log origin/$ghprbTargetBranch...$ghprbActualCommit | grep ^Submodule || true)" + # show diffs between $ghprbTargetBranch (where the merge is going) and + # $ghprbActualCommit (the tip of the branch that's merging) with '...', + # which is equivalent to diff $(git merge-base TB AC) AC, or "show + # diff from common ancestor of the target branch and this branch with the + # tip of this branch". With --submodule, also show detail of diff in submodules. + modified_submodules="$(git diff --submodule=log origin/${target_branch}...${actual_commit} | grep ^Submodule || true)" + test -n "${modified_submodules}" +} -if [[ -n "$modified_submodules" ]]; then +if has_modified_submodules "${ghprbTargetBranch}" "${ghprbActualCommit}"; then echo "Project has modified submodules!" echo $modified_submodules exit 1