diff --git a/.git-hooks/pre-commit b/.git-hooks/pre-commit index 87356d2fa..e28f82f9d 100755 --- a/.git-hooks/pre-commit +++ b/.git-hooks/pre-commit @@ -15,8 +15,20 @@ check_for_swiftformat() { format_staged_files() { git diff --diff-filter=d --staged --name-only | grep -e '\(.*\).swift$' | while read line; do - $formatter "${line}" - git add "$line" + + # format the stages changes in a file + + temporary_file="${line}.tmp.swift" + git show ":$line" > "$temporary_file" + + $formatter "$temporary_file" + $formatter "$line" + + blob=`git hash-object -w "$temporary_file"` + + git update-index --add --cacheinfo 100644 $blob "$line" + + rm "$temporary_file" done } diff --git a/.swiftformat b/.swiftformat index 89905fd2c..dea63e4bc 100644 --- a/.swiftformat +++ b/.swiftformat @@ -4,3 +4,4 @@ --trimwhitespace nonblank-lines --self init-only --stripunusedargs closure-only +--headers ignore \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f80cf3149..8e6092f23 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,10 +11,12 @@ This project makes use of the following tools: In order to benefit please ensure you have [Homebrew](https://brew.sh) installed on your system and then run the following commands inside the project directory: -`cd /path/to/this/repo` -`brew update` -`brew bundle` -`git config --local --add core.hooksPath .git-hooks` +``` +cd /path/to/this/repo +brew update +brew bundle +git config --local --add core.hooksPath .git-hooks +``` With these steps completed each time you build your code will be linted, and each time you commit your code will be formatted.