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