Fix RuboCop lints in StagedFile

Add some parentheses around the parameters for two method definitions in
`StagedFile`.

Change-Id: If78f7ee668256c24a02c9333558b7e6fd2081d99
Reviewed-on: https://gerrit.causes.com/25157
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Joe Lencioni <joe.lencioni@causes.com>
Update list of plugins in readme

We have added a few plugins that were not listed in the README.md file:

  - commit_msg/hard_tabs.rb
  - commit_msg/single_line_subject.rb
  - pre_commit/ruby_style.rb

This was easily accomplished with vim, by executing:

  :r ! tree lib/overcommit/plugins

Change-Id: I96582b0318ef785af9cd158c1a1330878f295f85
Reviewed-on: https://gerrit.causes.com/25177
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Joe Lencioni <joe.lencioni@causes.com>
Teach StagedFile which lines were changed

In order to support complex hook checks such as only returning an error
when a lint is detected on a line that a user touched, a `lines_changed`
method was added to the `StagedFile` class, which returns a set of
numbers representing the lines that were changed (1-based).

In the process, specs where added for the `StagedFile` class (as it
previously didn't have any). In order to support this, a module
`GitSpecHelpers` was added with functionality to make working with `git`
repositories a little easier. This was necessary to test `StagedFile`,
since its implementation is tightly coupled to using `git`.

Change-Id: Id3781a994d670f83979e08d77035fec97d0345ee
Reviewed-on: https://gerrit.causes.com/25158
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane@causes.com>
Don't cache result of modified_files

In the process of adding specs for the whitespace linter, I discovered
that running the specs in isolation worked, but running the entire suite
would hang.

Investigation revealed that because we were caching the result of
`modified_files`, any test which caused `modified_files` to be called
would cause that value to be cached for later calls. This resulted in
the whitespace check spec hanging because `grep` would be invoked with
no command-line arguments (since a previous test had cached
`modified_files` as an empty list).

Since we aren't invoking this method very often, I opted to remove the
caching as a simple solution.

I also removed an unnecessary class name from a method call to
`modified_files`.

Change-Id: Icf2c8a990e5974a1b22862f6f0ea660896465edc
Reviewed-on: https://gerrit.causes.com/25159
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane@causes.com>
Add missing parameter to block definitions

The custom matcher was missing a parameter in the block definitions for
the failure cases. This wasn't noticed because our test suite was
designed to pass, not fail (and thus this code would never get
executed).

Adding in the `check` parameter solves the problem.

Change-Id: I1b8a8c4164d50add9c4f44be65f78a64deccc093
Reviewed-on: https://gerrit.causes.com/25160
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane@causes.com>
Add spec for Whitespace check

Now that we have a convenient way to test anything involving
`StagedFile`s, we should try to add tests for these files.

Change-Id: If1c6cfee179cbd2dd13f2ed450b04f23cbe19195
Reviewed-on: https://gerrit.causes.com/25161
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane@causes.com>
Automatically filter staged files in check output

When a check ran against a staged file and had output that mentioned
that staged file, it would have to perform the additional task of
replacing the temporary file name for the staged file with the original
file name, via the `filter_string` method of the `StagedFile`.

We can DRY things up by having `BaseHook` automatically filter any
output returned by checks, allowing us to delete a number of duplicate
lines.

Change-Id: I829c512a8e58c70dae9551a963f2097a33eba2f1
Reviewed-on: https://gerrit.causes.com/25162
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane@causes.com>
Condense Ruby style output

The `rubocop` executable was outputting a lot of unnecessary text. Add
the `--format=emacs` and `--silent` flags to make the output more
concise.

Change-Id: Ib393c856e70327c4d670e9d57b19f39fc9b01f4e
Reviewed-on: https://gerrit.causes.com/25163
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane@causes.com>
Teach Ruby style check to treat unmodified lines as warnings

This check can get a bit noisy when working in a file with a lot of
lints which weren't caused by you. Rather than have the check report
errors for all style offenses in the file, we change the behaviour to
only count errors for lines actually touched by the diff.

Change-Id: Iafb49ac3ea4769c9541fd4910dee28e3eba9d506
Reviewed-on: https://gerrit.causes.com/25164
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane@causes.com>
Cut version 0.2.0

Change-Id: I8f91fa7b12a3a745c2ffb87e467a0fa8251c15bf
Reviewed-on: https://gerrit.causes.com/25165
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane@causes.com>
Simplify repo helper in GitSpecHelpers

Condense two separate calls to `Dir.chdir(path)` into a single call with
a block passed in.

Change-Id: I41b089981414d4f02757740e411f336d5e18102a
Reviewed-on: https://gerrit.causes.com/25222
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane@causes.com>
Always call to_s on output for checks

If a check returned a non-string object for its output, the hook would
fail with an error due to `empty?` not being defined for the object in
question.

To fix this, we explicitly call `to_s` on the output before checking if
it's empty. This also handles the case when there is no output, as
`nil.to_s` is just the empty string.

Change-Id: I1d18e905addc2749f407cf37e1d92dd433d8014b
Reviewed-on: https://gerrit.causes.com/25226
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane@causes.com>
Rename changelog to uppercase form

This is the standard name format for changelog files in other
repositories.

Change-Id: Ied94b19a04c1a463373c6ed3962bd621ff756582
Reviewed-on: https://gerrit.causes.com/25227
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane@causes.com>
Cut version 0.2.1

Change-Id: I86c59cd8be4cac97f45c00869ae38fb2d2c4d67a
Reviewed-on: https://gerrit.causes.com/25228
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane@causes.com>
Syntax check rake files

I added the ability to specify multiple file types for an overcommit
check, and made it check ruby style and syntax on rake files as well.

Change-Id: Ib737af6c9d9a8fd3b66c2ce0558e1bb51f3a7d85
Reviewed-on: https://gerrit.causes.com/25541
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane@causes.com>
Fix checks which return list of lines

cdc4c20a introduced a change that didn't properly handle the display of
checks which returned a list of lines. Instead of returning each element
of the list on its own line as originally intended, it would display the
literal list contents e.g. `["line 1", "line 2", ...]`.

This corrects the issue by Array-izing and flattening the output. For
nil or empty output, this will continue to return an empty string. For
lists, it will return that output properly converted to a string with
newlines as necessary. For any other output, it will return the original
string.

Change-Id: Id62190835e9a7dd35c58d3807361b677fd594381
Reviewed-on: https://gerrit.causes.com/25542
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane@causes.com>
Fix file type filtering for staged files

Commit ce42f5a introduced a bug through the use of `ends_with?` instead
of `end_with?` and referencing a non-existent `filetypes` attribute.

This change corrects the use of `end_with?` and renames the class
`filetype` attribute to `filetypes` to reduce confusion, since it
technically contains an array of extensions instead of a single file
type now.

Change-Id: Ief7df9f925f19308873a39a464e6a355a2ffb07f
Reviewed-on: https://gerrit.causes.com/25555
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Aaron Neyer <aaron.neyer@causes.com>
Indent check output lines under check name

When overcommit reported errors or warnings, its output format was a bit
odd since it would only indent the first line of output. This modifies
the output to add an indent after every newline character (except the
last) so that all output appears nested under the name of the check.

I also switched an unrelated string to use single quotes.

Change-Id: I0f2d3522eca3c4d475f965dd6b014a0c388c8f6b
Reviewed-on: https://gerrit.causes.com/25556
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Aaron Neyer <aaron.neyer@causes.com>
Cut version 0.2.2

Change-Id: I4614e6ca3745f42728d91f22347e43015e9f92af
Reviewed-on: https://gerrit.causes.com/25557
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Aaron Neyer <aaron.neyer@causes.com>
Fix "Argument list too long"

While using rbenv and commiting a submodule commit with a large number
of commits causes an "Argument list too long".

Instead of passing a large variable, pass in the ref and shell out to
git to append the submodule changes.

Change-Id: Iaa4981c3c1998174430e08a2c06fba9c4f70eee4
Reviewed-on: https://gerrit.causes.com/26338
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Greg Hurrell <greg@causes.com>
Reviewed-by: Lann Martin <lann@causes.com>
Reviewed-by: John Skopis <john.skopis@causes.com>
Tested-by: John Skopis <john.skopis@causes.com>