Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option --patterns-from-stdin and Git hook scripts update #1606

Merged
merged 5 commits into from Sep 27, 2022
Merged

Option --patterns-from-stdin and Git hook scripts update #1606

merged 5 commits into from Sep 27, 2022

Conversation

mfederczuk
Copy link
Contributor

@mfederczuk mfederczuk commented Aug 24, 2022

Description

This PR adds the options --patterns-from-stdin[=<delimiter>] and -z that'll read patterns separated by a delimiter (default is newline, giving an empty string or using the -z option is NUL byte) and add them to the patterns given on the command line.

Since the --stdin option would already read from stdin, it'll throw an exception if both --stdin and --patterns-from-stdin/-z are given.

These options were primarily added to update the Git hook scripts.
The main problems with the old ones were that files with special characters (e.g.: newline) in the name would not be passed along correctly (since Git quotes those filenames without the -z option) and that the --no-run-if-empty hack wouldn't work on non-GNU systems. (since that option is a GNU extension)

Checklist

  • PR description added
  • tests are added
  • KtLint has been applied on source code itself and violations are fixed
  • documentation is updated
  • CHANGELOG.md` is updated

@paul-dingemans
Copy link
Collaborator

Thnx for your contribution. I have to park this for a while until problems in latest release have been mitigated. I will come back to you in a couple of weeks.

Copy link
Collaborator

@paul-dingemans paul-dingemans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tnx for your patience. Please address the review remarks.

docs/install/cli.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
* 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`
@mfederczuk mfederczuk changed the title Options --patterns-from-stdin and -z and Git hook scripts update Option --patterns-from-stdin and Git hook scripts update Sep 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants