git-fmt

Custom git command for formatting code. https://github.com/hjwylde/git-fmt

Version on this page:0.4.1.0
LTS Haskell 7.24:0.4.1.0
Stackage Nightly 2016-11-06:0.4.1.0
Latest on Hackage:0.4.1.0
BSD3 licensed by Henry J. Wylde
Maintained by public@hjwylde.com

Module documentation for 0.4.1.0

There are no documented modules for this package.

git-fmt

Project Status: Wip - Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. Build Status Release git-fmt on Stackage LTS git-fmt on Stackage Nightly

Custom git command for formatting code. git-fmt provides a wrapper around omnifmt, an automatic code formatter. It adds the ability to operate on specific tracked files in the repository.

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 (recommended) or Cabal.

Using stack:

stack install git-fmt
export PATH=$PATH:~/.local/bin

Using Cabal:

cabal-install git-fmt
export PATH=$PATH:~/.cabal/bin

Usage

The git-fmt binary provides an interface for selecting files and piping them through external pretty-printers. It supports both prettifying the files immediately and performing dry-runs to see which files are ugly. Given that it uses the omnifmt library underneath, the syntax and features are quite similar. The main difference is that git-fmt restricts files to being tracked by the git repository and that by default it only operates on files in the index.

The basics:

git-fmt operates only on tracked git files (thus it implicitly respects the '.gitignore' file). By default it operates on files in the index (i.e., --operate-on head). It is possible to operate on all tracked files (--operate-on-tracked) or on a specific reference (--operate-on REF). The REF argument is passed directly into git diff REF --name-only, so you can even play with ranges such as master....

Passing arguments to git-fmt will narrow down the operation files. For example, git fmt --operate-on-tracked src/ will format all tracked files under 'src/' and git fmt --operate-on head src/ will format all files in the index under 'src/'.

Modes:

git-fmt can run in three different modes, normal, dry-run and diff.

The normal and dry-run modes act the same as omnifmt. Diff mode however uses git diff as opposed to diff. By default the diff isn't paged, so to get output similar to git diff or git log it is recommended to use [-p|--paginate], e.g., git -p fmt -m diff.

NB: it isn't possible to pipe the diff into git apply due to the destination file path header.

Configuration

git-fmt delegates to omnifmt for configuration, see here for documentation and examples.

Auto-completion

Add the following (depending on your shell) to include support for auto-completion.

Bash:

source <(git-fmt --bash-completion-script `which git-fmt`)

zsh:

autoload -Uz bashcompinit && bashcompinit
source <(git-fmt --bash-completion-script `which git-fmt`)

NB: auto-completion doesn't work well with git's command macro. I.e., git fmt <TAB> won't work, but git-fmt <TAB> will. #71 will remain open until this is addressed.

Changes

Changelog

Upcoming

v0.4.1.0

Minor

  • Added bash completion for --mode and arguments. (#71)

Revisions

  • Changed path outputs to be relative to the root directory. (#69)
  • Fixed a bug where --operate-on didn't work in subdirectories. (#69)

v0.4.0.0

Major

  • Extracted omnifmt out to git@github.com:hjwylde/omnifmt. (#41)

v0.3.1.2

Revisions

  • Fixed a bug causing prettifying to fail across filesystem boundaries. (#72)

v0.3.1.1

Revisions

  • Fixed a bug causing the program to hang when not in the root directory. (#66)
  • Fixed a bug that omitted searching the drive for a config file. (#66)
  • Fixed a bug where output files could be created outside of the temp directory. (#68)

v0.3.1.0

Minor

  • Added timeout wrapper for the program command. (#52)
  • Added diff mode. (#23)

v0.3.0.5

Revisions

  • Fixed a bug causing prettifying to fail across filesystem boundaries. (#72)

v0.3.0.4

Revisions

  • Fixed a bug causing the program to hang when not in the root directory. (#66)
  • Fixed a bug that omitted searching the drive for a config file. (#66)
  • Fixed a bug where output files could be created outside of the temp directory. (#68)

v0.3.0.3

Revisions

  • Restricted use of --operate-on-tracked and --operate-on REF at the same time. (#65)
  • Removed long option for help text (as git overrides it for man pages). (#65)

v0.3.0.2

Revisions

  • Fixed a bug where passing arguments didn't properly narrow down the operation files. (#64)

v0.3.0.1

Revisions

  • Relaxed version constraints. (#63)

v0.3.0.0

Major

  • Restricted arguments to being inside the repository. (#34)
  • Refactored library to use pipes. (#32)
  • Made Options and Version modules private. (#62)
  • Renamed library modules to Omnifmt. (#62)
  • Refactored pipeline to feed and consume triples. (#61)
  • Set default --operate-on to head. (#28)

Minor

  • Changed "not found" status to print as debug message. (#61)
  • Added "unsupported" status as debug message. (#61)
  • Added --operate-on-tracked and --operate-on REF options. (#28)

v0.2.2.1

Revisions

  • Fixed a bug causing prettifying to fail across filesystem boundaries. (#72)

v0.2.2.0

Minor

  • Added --threads option to change the number of threads for parallelisation. (#54)

Revisions

  • Added quoting to the command variables during substitution. (#59)
  • Changed parallelisation to use the number of capabilities (and processors) for the number of threads by default. (#54)

v0.2.1.2

Revisions

  • Fixed a bug causing prettifying to fail across filesystem boundaries. (#72)

v0.2.1.1

Revisions

  • Fixed a bug where passing arguments would only work when running in the git directory. (#57)

v0.2.1.0

Minor

  • Added default use of stdin and stdout when variables not specified in a program command. (#49)

v0.2.0.2

Revisions

  • Fixed a bug causing prettifying to fail across filesystem boundaries. (#72)

v0.2.0.1

Revisions

  • Fixed a bug where passing arguments would only work when running in the git directory. (#57)

v0.2.0.0

Major

  • Removed --list-ugly and --dry-run options. (#29)
  • Restricted use of --quiet and --verbose at the same time. (#35)
  • Updated project structure to delegate pretty printing to other binaries. (#38)
  • Added a .omniyaml.yaml config file. (#38)

Minor

  • Added --mode option (either normal or dry-run). (#29)
  • Added --null option (use the null terminator as the delimiter for inputs). (#27)
  • Added support for directories as arguments (directories include all files within recursively). (#30)
  • Added parallelisation. (#48)

Revisions

  • Added a warning for when files aren't found. (#29)
  • Updated internal use of git ls-files to use the null terminator option. (#27)
  • Fixed debug log messages to have timestamp and log level on all lines. (#33)
  • Tidied up error messages from git. (#40)
  • Tidied up error messages from parsing the config. (#43)

v0.1.0.3

Revisions

  • Fixed a bug where passing arguments would only work when running in the git directory. (#57)

v0.1.0.2

Revisions

  • Fixed a bug where UTF-8 characters in strings weren't printed properly. (#26)

v0.1.0.1

Revisions

  • Fixed a bug where integers were printed as rationals. (#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.

comments powered byDisqus