-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Option
--patterns-from-stdin
and Git hook scripts update (#1606)
* Add `--patterns-from-stdin` option to CLI * Update Git hook scripts - Instead of using `grep` to filter Kotlin (script) files, doing it directly with `git diff` - Using the `-z` option for the `git` command and the `--patterns-from-stdin=''` option for the `ktlint` command so that files with special characters are handled properly. This also eliminates having to use `xargs` with that `--no-run-if-empty` hack - Quoted the `origin/$(git rev-parse --abbref-ref HEAD)` argument, just in case - Removed the `if` statement at the end that checks the exit code, since it's unnecessary - it's basically the same as `if (condition) return true else return false` Co-authored-by: paul-dingemans <paul-dingemans@users.noreply.github.com>
- Loading branch information
1 parent
8e78581
commit d1e4fe8
Showing
11 changed files
with
225 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 4 additions & 5 deletions
9
ktlint/src/main/resources/ktlint-git-pre-commit-hook-android.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
#!/bin/sh | ||
# https://github.com/pinterest/ktlint pre-commit hook | ||
# On Linux xargs must be told to do nothing on no input. On MacOS (linux distribution "Darwin") this is default behavior and the xargs flag "--no-run-if-empty" flag does not exists | ||
[ "$(uname -s)" != "Darwin" ] && no_run_if_empty=--no-run-if-empty | ||
git diff --name-only --cached --relative | grep '\.kt[s"]\?$' | xargs $no_run_if_empty ktlint --android --relative | ||
if [ $? -ne 0 ]; then exit 1; fi | ||
|
||
# <https://github.com/pinterest/ktlint> pre-commit hook | ||
|
||
git diff --name-only -z --cached --relative -- '*.kt' '*.kts' | ktlint --android --relative --patterns-from-stdin='' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
#!/bin/sh | ||
# https://github.com/pinterest/ktlint pre-commit hook | ||
# On Linux xargs must be told to do nothing on no input. On MacOS (linux distribution "Darwin") this is default behavior and the xargs flag "--no-run-if-empty" flag does not exists | ||
[ "$(uname -s)" != "Darwin" ] && no_run_if_empty=--no-run-if-empty | ||
git diff --name-only --cached --relative | grep '\.kt[s"]\?$' | xargs $no_run_if_empty ktlint --relative | ||
if [ $? -ne 0 ]; then exit 1; fi | ||
|
||
# <https://github.com/pinterest/ktlint> pre-commit hook | ||
|
||
git diff --name-only -z --cached --relative -- '*.kt' '*.kts' | ktlint --relative --patterns-from-stdin='' |
9 changes: 4 additions & 5 deletions
9
ktlint/src/main/resources/ktlint-git-pre-push-hook-android.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
#!/bin/sh | ||
# https://github.com/pinterest/ktlint pre-push hook | ||
# On Linux xargs must be told to do nothing on no input. On MacOS (linux distribution "Darwin") this is default behavior and the xargs flag "--no-run-if-empty" flag does not exists | ||
[ "$(uname -s)" != "Darwin" ] && no_run_if_empty=--no-run-if-empty | ||
git diff --name-only HEAD origin/$(git rev-parse --abbrev-ref HEAD) | grep '\.kt[s"]\?$' | xargs $no_run_if_empty ktlint --android --relative | ||
if [ $? -ne 0 ]; then exit 1; fi | ||
|
||
# <https://github.com/pinterest/ktlint> pre-push hook | ||
|
||
git diff --name-only -z HEAD "origin/$(git rev-parse --abbrev-ref HEAD)" -- '*.kt' '*.kts' | ktlint --android --relative --patterns-from-stdin='' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
#!/bin/sh | ||
# https://github.com/pinterest/ktlint pre-push hook | ||
# On Linux xargs must be told to do nothing on no input. On MacOS (linux distribution "Darwin") this is default behavior and the xargs flag "--no-run-if-empty" flag does not exists | ||
[ "$(uname -s)" != "Darwin" ] && no_run_if_empty=--no-run-if-empty | ||
git diff --name-only HEAD origin/$(git rev-parse --abbrev-ref HEAD) | grep '\.kt[s"]\?$' | xargs $no_run_if_empty ktlint --relative | ||
if [ $? -ne 0 ]; then exit 1; fi | ||
|
||
# <https://github.com/pinterest/ktlint> pre-push hook | ||
|
||
git diff --name-only -z HEAD "origin/$(git rev-parse --abbrev-ref HEAD)" -- '*.kt' '*.kts' | ktlint --relative --patterns-from-stdin='' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.