]> git.apps.os.sepia.ceph.com Git - ceph-build.git/commitdiff
ceph-pr-submodules: extract the check into a function
authorKefu Chai <tchaikov@gmail.com>
Mon, 20 Dec 2021 12:59:46 +0000 (20:59 +0800)
committerKefu Chai <tchaikov@gmail.com>
Mon, 20 Dec 2021 13:48:47 +0000 (21:48 +0800)
prepare for the next commit which add an escape rule

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
ceph-pr-submodules/build/build

index 747bc73dfacf6228ca473a564d61e0ac634c0a7f..339dcb187bbdf08651b63f832b8097853dc63f71 100644 (file)
@@ -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