diff --git a/scripts/diff_against_branch.sh b/scripts/diff_against_branch.sh index 077c904..4712766 100755 --- a/scripts/diff_against_branch.sh +++ b/scripts/diff_against_branch.sh @@ -19,7 +19,17 @@ declare -a ERROR_FILES ORIGIN=${1:-c4t} -git fetch origin $ORIGIN +# Color definition for bash output +RED='\033[0;31m' +GREEN='\033[0;32m' +PURPLE='\033[0;35m' +NC='\033[0m' # No Color + +function check_filesystem_changes { + FILE=$1 + echo -e "❌ ${RED}[FAIL] ERROR${NC}: Structural filesystem change for already existing file detected (deleted/renamed/etc)! File: $FILE" + ERROR_FILES+=("$FILE") +} function check_added_file { FILE=$1 @@ -34,17 +44,15 @@ function check_added_file { OTHER_FILE=$(echo $FILE | sed -e "s#/v$FILE_VERSION/#/v$(( FILE_VERSION - 1))/#") echo - echo "#############################################################################" - echo "## Detected newly added file: $FILE" - echo "## Version: $FILE_VERSION" - echo "## Comparing against $ORIGIN/$OTHER_FILE" - echo "#############################################################################" - echo + echo -e "🆕 Detected newly added file: ${PURPLE}$FILE${NC}" + echo -e "🔢 Version: ${PURPLE}$FILE_VERSION${NC}" + echo -e "🔃 Comparing against ${PURPLE}$ORIGIN/$OTHER_FILE${NC}" GIT_PAGER=cat git diff --exit-code origin/$ORIGIN:$OTHER_FILE $FILE if [[ "$?" == "0" ]] ; then - echo "## No change detected! (weird?)" + echo "❓ No change detected! (weird?)" fi + echo } function check_modified_file { @@ -52,15 +60,12 @@ function check_modified_file { OTHER_FILE=$FILE echo - echo "#############################################################################" - echo "## Detected modified file: $FILE" - echo "## Comparing against $ORIGIN/$OTHER_FILE" - echo "#############################################################################" - echo + echo -e "🔧 Detected modified file: ${PURPLE}$FILE${NC}" + echo -e "🔃 Comparing against ${PURPLE}$ORIGIN/$OTHER_FILE${NC}" GIT_PAGER=cat git diff --exit-code origin/$ORIGIN:$OTHER_FILE $FILE if [[ "$?" == "0" ]] ; then - echo "## No change detected! (weird?)" + echo "❓ No change detected! (weird?)" fi # Check here if the file has any structure modifications, if yes return @@ -68,37 +73,41 @@ function check_modified_file { # against the c4t branch diff -w -B - <(git show origin/$ORIGIN:$OTHER_FILE | sed -e "s#//.*##g") < <(cat $FILE | sed -e "s#//.*##g") > /dev/null if [[ "$?" != "0" ]] ; then - echo - echo "## ❌ [FAIL] ERROR: Structural change detected in already existing file: $FILE" + echo -e "❌ ${RED}[FAIL] ERROR${NC}: Structural change detected in already existing file: ${PURPLE}$FILE${NC}" ERROR_FILES+=("$FILE") else - echo - echo "## ✅ [PASS] INFO: No structural change detected. The changes should only be in the comments." + echo -e "✅ ${GREEN}[PASS] INFO${NC}: No structural change detected. The changes should only be in the comments." fi + echo } +echo -e "⏳ Fetching the latest changes from the origin branch: ${PURPLE}$ORIGIN${NC}" +git fetch origin $ORIGIN > /dev/null 2>&1 + +echo -e "🔍 Checking for illegal filesystem changes like removing/moving existing files" while read FILE ; do - check_added_file $FILE -done < <(git diff --name-status origin/$ORIGIN | grep -P "^A.*" | grep -oP "proto/.*") + check_filesystem_changes $FILE +done < <(git diff --diff-filter=am --name-status origin/$ORIGIN | grep -oP "proto/.*") +echo -e "🔍 Checking for added files to print out the diff of the new version against the previous version" +while read FILE ; do + check_added_file $FILE +done < <(git diff --diff-filter=A --name-status origin/$ORIGIN | grep -oP "proto/.*") +echo -e "🔍 Checking for modifications in existing files to catch unwanted structural changes" while read FILE ; do check_modified_file $FILE -done < <(git diff --name-status origin/$ORIGIN | grep -P "^M.*" | grep -oP "proto/.*") +done < <(git diff --diff-filter=M --name-status origin/$ORIGIN | grep -oP "proto/.*") if [ ${#ERROR_FILES[@]} -gt 0 ] ; then echo - echo "#############################################################################" - echo "## ❌ Found ${#ERROR_FILES[@]} errors while doing the diff" - echo "## Please check the following files: " + echo "❌ Found ${#ERROR_FILES[@]} error(s) while doing the diff" + echo "📂 Please check the following files: " for file in ${ERROR_FILES[@]} ; do - echo "## -> $file" + echo -e " -> ${RED}$file${NC}" done - echo "#############################################################################" exit 1 fi echo -echo "##########################" -echo "## ✅ No issues found! ##" -echo "##########################" \ No newline at end of file +echo "✅ No issues found!" \ No newline at end of file