Skip to content

Instantly share code, notes, and snippets.

@wadoon
Created July 26, 2022 13:24
Show Gist options
  • Save wadoon/176414150a86b7d39e19c135bf0c69a6 to your computer and use it in GitHub Desktop.
Save wadoon/176414150a86b7d39e19c135bf0c69a6 to your computer and use it in GitHub Desktop.
#!/bin/bash
echo "Review Script."
REVIEW_BASE=${REVIEW_BASE:-master}
if [ ! -z $1 ]; then
git switch $1 || exit 1
fi
echo "Reviewing of $1 against $REVIEW_BASE"
BASE_COMMIT=$(git merge-base HEAD $REVIEW_BASE)
echo "Following has been changed:"
git diff --stat $BASE_COMMIT
changed_files=$(git diff --name-only $BASE_COMMIT)
TMP_FOLDER="/tmp/old_version"
UF_FOLDER="$TMP_FOLDER/unformatted"
F_FOLDER="$TMP_FOLDER/formatted"
mkdir -p $TMP_FOLDER/{un,}formatted/{base,feature}
function format() {
case $1 in
*.c|*.java|*.cpp|*.hpp|*.cxx)
echo "Formatting $1 to $2 with clang"
clang-format --style=Microsoft $1 > $2
;;
*)
echo "No formatting for $1"
cp $1 $2
;;
esac
}
DIFF=${DIFF:-delta}
DIFF_PREFIX=${DIFF_PREFIX:-cat}
for file in $changed_files; do
echo "Investigating changed file: $file"
base=$UF_FOLDER/base/$(basename $file)
feature=$(readlink -f $file)
f_base=$F_FOLDER/base/$(basename $file)
f_feature=$F_FOLDER/feature/$(basename $file)
if [ ! -f $feature ]; then
echo "\t> File got deleted!"
else
git show $BASE_COMMIT:$file > $base
if [ $? = 0 ]; then
format $base $f_base
format $feature $f_feature
$DIFF $f_base $f_feature #| diff-so-fancy
fi
fi
read n
done
#diff $tmpA $tmpB | diff-so-fancy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment