Skip to content

Commit

Permalink
Add support for formatting all or only added / modified files
Browse files Browse the repository at this point in the history
  • Loading branch information
maicki committed Mar 6, 2019
1 parent fea7091 commit e8129cf
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions format
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,37 @@ DIR="$( cd "$( dirname "$0" )" && pwd)"
# Define top level project directory
PROJECT_DIR="${DIR}"

METHOD="GIT"
if [ -n "$1" ]; then
METHOD=$1
fi

echo $METHOD

# Paths to format
MONITOR=()
MONITOR+=( "${PROJECT_DIR}/Source" )

# Format all files
for FILE in $(find ${MONITOR[*]} -type f \( -iname "*.mm" -o -iname "*.m" -o -iname "*.h" \))
do
clang-format -style=file -i "$FILE" &
done
if [ "$METHOD" == "ALL" ]; then
# Format all Source files
for FILE in $(find ${MONITOR[*]} -type f \( -iname "*.mm" -o -iname "*.m" -o -iname "*.h" \))
do
echo "$FILE"
# clang-format -style=file -i "$FILE" &
done
elif [ "$METHOD" == "GIT" ]; then
# Gather all added or modified files from git and format them
CHANGED_FILES=$(git ls-files --other --modified --exclude-standard | grep ".*[\.m|\.mm|\.h|\.hpp]$")
for CHANGED_FILE in $CHANGED_FILES
do
echo "${PROJECT_DIR}/$CHANGED_FILE"
# clang-format -style=file -i "${PROJECT_DIR}/$CHANGED_FILE" &
done
else
# TODO: Error for wrong input
echo "Wrong parameter passed in. Supported: ALL or GIT"
fi


# Wait until all clang-format invoctations are done
wait

0 comments on commit e8129cf

Please sign in to comment.