git-fmt 0.2.2.0 → 0.2.2.1
raw patch · 4 files changed
+197/−3 lines, 4 files
Files
- CHANGELOG.md +100/−0
- README.md +86/−0
- git-fmt.cabal +3/−1
- src/Git/Fmt.hs +8/−2
+ CHANGELOG.md view
@@ -0,0 +1,100 @@+## Changelog++#### Upcoming++#### v0.2.2.1++*Revisions*++* Fixed a bug causing prettifying to fail across filesystem boundaries. ([#72](https://github.com/hjwylde/git-fmt/issues/72))++#### v0.2.2.0++*Minor*++* Added `--threads` option to change the number of threads for parallelisation. ([#54](https://github.com/hjwylde/git-fmt/issues/54))++*Revisions*++* Added quoting to the command variables during substitution. ([#59](https://github.com/hjwylde/git-fmt/issues/59))+* Changed parallelisation to use the number of capabilities (and processors) for the number of+ threads by default. ([#54](https://github.com/hjwylde/git-fmt/issues/54))++#### v0.2.1.2++*Revisions*++* Fixed a bug causing prettifying to fail across filesystem boundaries. ([#72](https://github.com/hjwylde/git-fmt/issues/72))++#### v0.2.1.1++*Revisions*++* Fixed a bug where passing arguments would only work when running in the git directory. ([#57](https://github.com/hjwylde/git-fmt/issues/57))++#### v0.2.1.0++*Minor*++* Added default use of stdin and stdout when variables not specified in a program command. ([#49](https://github.com/hjwylde/git-fmt/issues/49))++#### v0.2.0.2++*Revisions*++* Fixed a bug causing prettifying to fail across filesystem boundaries. ([#72](https://github.com/hjwylde/git-fmt/issues/72))++#### v0.2.0.1++*Revisions*++* Fixed a bug where passing arguments would only work when running in the git directory. ([#57](https://github.com/hjwylde/git-fmt/issues/57))++#### v0.2.0.0++*Major*++* Removed `--list-ugly` and `--dry-run` options. ([#29](https://github.com/hjwylde/git-fmt/issues/29))+* Restricted use of `--quiet` and `--verbose` at the same time. ([#35](https://github.com/hjwylde/git-fmt/issues/35))+* Updated project structure to delegate pretty printing to other binaries. ([#38](https://github.com/hjwylde/git-fmt/issues/38))+* Added a `.omniyaml.yaml` config file. ([#38](https://github.com/hjwylde/git-fmt/issues/38))++*Minor*++* Added `--mode` option (either `normal` or `dry-run`). ([#29](https://github.com/hjwylde/git-fmt/issues/29))+* Added `--null` option (use the null terminator as the delimiter for inputs). ([#27](https://github.com/hjwylde/git-fmt/issues/27))+* Added support for directories as arguments (directories include all files within recursively). ([#30](https://github.com/hjwylde/git-fmt/issues/30))+* Added parallelisation. ([#48](https://github.com/hjwylde/git-fmt/issues/48))++*Revisions*++* Added a warning for when files aren't found. ([#29](https://github.com/hjwylde/git-fmt/issues/29))+* Updated internal use of `git ls-files` to use the null terminator option. ([#27](https://github.com/hjwylde/git-fmt/issues/27))+* Fixed debug log messages to have timestamp and log level on all lines. ([#33](https://github.com/hjwylde/git-fmt/issues/33))+* Tidied up error messages from git. ([#40](https://github.com/hjwylde/git-fmt/issues/40))+* Tidied up error messages from parsing the config. ([#43](https://github.com/hjwylde/git-fmt/issues/43))++#### v0.1.0.3++*Revisions*++* Fixed a bug where passing arguments would only work when running in the git directory. ([#57](https://github.com/hjwylde/git-fmt/issues/57))++#### v0.1.0.2++*Revisions*++* Fixed a bug where UTF-8 characters in strings weren't printed properly. ([#26](https://github.com/hjwylde/git-fmt/issues/26))++#### v0.1.0.1++*Revisions*++* Fixed a bug where integers were printed as rationals. ([#25](https://github.com/hjwylde/git-fmt/issues/25))++#### v0.1.0.0++This is first release of the `git-fmt` binary!+It provides a basic syntax for formatting files in a git repository.+Currently only JSON is supported.+
+ README.md view
@@ -0,0 +1,86 @@+# git-fmt++[](http://www.repostatus.org/#wip)+[](https://travis-ci.org/hjwylde/git-fmt)+[](https://github.com/hjwylde/git-fmt/releases/latest)++(Side note: the formatting component of this project will eventually be split out and named omnifmt.)++`git-fmt` was created to make prettifying code easy.+It adds a custom (easy to use) command to Git that formats code through external pretty-printers.++Formatted code is:++* Easier to write: never worry about minor formatting concerns while hacking away.+* Easier to read: when all code looks the same you need not mentally convert others' formatting+ style into something you can understand.+* Easier to maintain: mechanical changes to the source don't cause unrelated changes to the file's+ formatting; diffs show only the real changes.+* Uncontroversial: never have a debate about spacing or brace position ever again.++(Bullet points taken from https://blog.golang.org/go-fmt-your-code.)++### Installing++Installing `git-fmt` is easiest done using either+ [stack](https://github.com/commercialhaskell/stack) (recommended) or+ [Cabal](https://github.com/haskell/cabal).++**Using stack:**++```bash+stack install git-fmt+export PATH=$PATH:~/.local/bin+```++**Using Cabal:**++```bash+cabal-install git-fmt+export PATH=$PATH:~/.cabal/bin+```++### Usage++The `git-fmt` binary wraps external pretty-printers and provides an interface for selecting files+ to prettify and performing dry-runs.+Rather than repeating it here, have a read of `git fmt -h` for how to call it.++#### Configuration++Configuration is done via an `.omnifmt.yaml` file in the git repository.+The file contains a list of *programs* that link *extensions* to a prettifying *command*, e.g.,+```yaml+haskell:+ extensions: ["hs", "lhs"]+ command: "stylish-haskell {{input}} > {{output}}"++javascript:+ extensions: ["js"]+ command: "js-beautify -f {{input}}"++json:+ extensions: ["json"]+ command: "json_pp"++ruby:+ extensions: ["rb"]+ command: "ruby-beautify"+```++Each command declares how to read the *input file* and how to write to the *output file*.+If the input variable is omitted, the file contents are fed to the command through `stdin`.+Likewise if the output variable is omitted, the pretty contents are read from `stdout`.+The output file is used to compare whether the original was pretty or ugly before writing to it.++The extensions field is pretty self explanatory, but if you use the same extension more than once+ then precedence goes to the program defined first.++#### Examples++See the [docs/example-configs/](https://github.com/hjwylde/git-fmt/tree/master/docs/example-configs/)+ directory for some common pretty-printers and their corresponding omnifmt config.+Just don't forget to actually call the config file `.omnifmt.yaml`!++**NB:** I haven't tested them fully, be careful in case one is buggy.+
git-fmt.cabal view
@@ -1,5 +1,5 @@ name: git-fmt-version: 0.2.2.0+version: 0.2.2.1 author: Henry J. Wylde maintainer: public@hjwylde.com@@ -16,6 +16,8 @@ cabal-version: >= 1.10 category: Development build-type: Simple++extra-source-files: CHANGELOG.md README.md source-repository head type: git
src/Git/Fmt.hs view
@@ -38,7 +38,8 @@ import Data.Yaml (prettyPrintParseException) import Data.Yaml.Include (decodeFileEither) -import Git.Fmt.Config as Config+import GHC.IO.Exception (IOErrorType (..))+import Git.Fmt.Config as Config import Git.Fmt.Exit import Git.Fmt.Process @@ -47,6 +48,7 @@ import System.Directory.Extra hiding (withCurrentDirectory) import System.Exit import System.FilePath+import System.IO.Error import System.IO.Temp -- | Options.@@ -125,7 +127,11 @@ normal filePath tmpFilePath = do $(logInfo) $ T.pack (filePath ++ ": prettified") - liftIO $ renameFile tmpFilePath filePath+ -- Try move the file, but if it's across a filesystem boundary then we may need to copy instead+ liftIO $ renameFile tmpFilePath filePath `catchIOError` \e ->+ if ioeGetErrorType e == UnsupportedOperation+ then copyFile tmpFilePath filePath >> removeFile tmpFilePath+ else ioError e dryRun :: (MonadIO m, MonadLogger m) => FilePath -> FilePath -> m () dryRun filePath _ = $(logInfo) $ T.pack (filePath ++ ": ugly")