Skip to content

Commit

Permalink
Fix - git precommit hook was a bit... over zealous 🤦 (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
mormaer authored Aug 26, 2023
1 parent 7379b0d commit fbe7e33
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
16 changes: 14 additions & 2 deletions .git-hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
--trimwhitespace nonblank-lines
--self init-only
--stripunusedargs closure-only
--headers ignore
10 changes: 6 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit fbe7e33

Please sign in to comment.