Partial Maven clean install after Git pull
Take a cleaner approach if you can

The current approach is basically a dirty hack to work around Maven's inability to do incremental builds.
I recommend to start looking into another more modern build system that is able to re-build just what needs to be rebuilt.
Such as Gradle.

Always double-quote variables in arguments

As a rule of thumb, always put double-quotes around variables used as arguments. For example in all these places, there should be double-quotes around the variables:


read -a GIT_DIFF_OUTPUT_ARY &lt;&lt;&lt; $GIT_DIFF_OUTPUT
...

GIT_DIFF_OUTPUT="$(git diff --name-status HEAD@{1} ${CURRENT_BRANCH})"
...

IFS='/' read -ra SPLIT &lt;&lt;&lt; $i
...

GIT_DIFF_OUTPUT_ARY_ROOT_PATH+=($path)
...

for val in ${GIT_DIFF_OUTPUT_ARY_ROOT_PATH[@]}
...

cd $val
...



Avoid performance pitfalls

For each path in the diff,
the script builds the array GIT_DIFF_OUTPUT_ARY_ROOT_PATH with the first two path segments,
and keeps the elements unique by not adding a value if it's already in the array.
As the size of the array grows, this becomes increasingly inefficient,
as this is quadratic time complexity.

I believe the paths printed by git diff is sorted by default.
You can take advantage of that:
track the previous element,
and only add a new value when it's different from the previous.
You will achieve better performance and without using the containsElement function.

Use the exit code directly in conditional expressions

Instead of this:


containsElement "$path" "${GIT_DIFF_OUTPUT_ARY_ROOT_PATH[@]}"
if [[ $? != 0 ]]
then
    #Add the path since it was not found
    GIT_DIFF_OUTPUT_ARY_ROOT_PATH+=($path)
fi



You could use the exit code of the function directly in a conditional:

if ! containsElement "$path" "${GIT_DIFF_OUTPUT_ARY_ROOT_PATH[@]}"
then
    #Add the path since it was not found
    GIT_DIFF_OUTPUT_ARY_ROOT_PATH+=($path)
fi


Get current Git branch name using native Git commands

Instead of this:

CURRENT_BRANCH="$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')"


This is a better, native way:

CURRENT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"


Use native Bash to get string length

This line tries to check the length of a variable:


if [[ "$(echo -n $i | wc -m)" != 1 ]]



Although -m is used, the possible values will not be multibyte,
so the solution is equivalent to using -c.
In this case, a better solution exists with native Bash:

if [[ ${#i} != 1 ]]


Use better variable names

i is good for simple counters. It's not a good name for anything else.

What is FORWARD? path_separator or pathsep would have been better.