Pop stash instead of applying

The `pop` was changed to `apply` in 8683da4a as a safety measure while
issue #55 was tracked down. The root cause was fixed in 205c0b46 and
released in v0.13.0. We should restore previous behavior so that the
stash is useful again.

Fixes #62.

Change-Id: I3d243accf80334323299bd19b71b1e295ef9cf9a
Reviewed-on: http://gerrit.causes.com/40371
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
Disable GuardClause Rubocop check

Change-Id: I2b4bed3a50f079c996c20282d962e924d8abddd2
Reviewed-on: http://gerrit.causes.com/40378
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
Fix line concatenation Rubocop lints

Change-Id: Ibd68d2d7969639f7c715d029f7645f4c564e7674
Reviewed-on: http://gerrit.causes.com/40379
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
Tested-by: jenkins <jenkins@causes.com>
Split up options parsing into helpers

This addresses a Rubocop lint, but more importantly provides some inline
documentation about the different types of options available, and groups
them accordingly.

Change-Id: If5070d143fc485a613917126368d61cf1c77cb79
Reviewed-on: http://gerrit.causes.com/40380
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
Disable EachWithObject Rubocop lint

Change-Id: I07be300742b194e73092f33fcb5fed7f9f3c705d
Reviewed-on: http://gerrit.causes.com/40381
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
Split out configuration validation into helper class

Validation of the configuration started making the `Configuration` class
a bit long. Separate out the concern into a separate helper class.

Change-Id: I267addc42240d235a23e03ff69be71a396a27613
Reviewed-on: http://gerrit.causes.com/40382
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
Extract concerns from HookContext::PreCommit into helper class

The `PreCommit` hook context was getting large due to it juggling a
large number of concerns related to working with `git`.

Extract these concerns into a helper `GitRepo` to make the code a little
more straightforward.

Change-Id: I7670c6e6196fcd81bfad215b92255818dd2574f8
Reviewed-on: http://gerrit.causes.com/40383
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
Quiet Rubocop lint in RailsSchemaUpToDate hook

The complexity here is necessary, and isolated such that we don't need
to worry about it.

Change-Id: I5e8e1f8dae188d861ea4221acad2b116d65f7e26
Reviewed-on: http://gerrit.causes.com/40384
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
Extract helpers from HookRunner methods

The `run_hook(s)` methods in `HookRunner` were a bit long. Extract
portions of them into helpers to improve readability.

Change-Id: I89acf7e23b3e44d11000fdda041622c3b2a19f2a
Reviewed-on: http://gerrit.causes.com/40385
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
Gracefully handle configuration error in JSCS hook

The error message output by `jscs` when no configuration file is present
changed at some point since this hook was first written.

Change the check to inspect the exit code of the process. Looking at the
source at https://github.com/mdevils/node-jscs/blob/master/lib/cli.js,
the CLI appears to return 2 when a lint was found, 1 when some other
problem occurs, and 0 when no lints were found.

Change-Id: Id1a1d7b6d751f17edc03cea3960701ba728246f7
Reviewed-on: http://gerrit.causes.com/40418
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
Fix performance regression in file include/exclude logic

Commit 0e3540d introduced a performance regression where running
Overcommit in repositories with a large number of files that could
potentially apply to a given hook (even if they weren't being staged)
would result in a very slow hook run.

This was due to us switching from `File.fnmatch?` to `Dir.glob` because
at the time the behavior of the latter was what we were trying to
achieve. However, this approach also scans the actual filesystem, making
it slow.

Further investigation revealed that `File.fnmatch?` can take an
additional flag that changes the behavior to act more like `Dir.glob`,
namely resulting in `**/*.rb` matching all Ruby files, both at the root
as well as in subdirectories.

Change-Id: I1e4e66e8aa50d72381301762d5642133515a0b85
Reviewed-on: http://gerrit.causes.com/40419
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
Enable wildcards in globs to match dotfiles

The default behavior of Ruby's glob implementation is for the asterisk
`*` to not match files beginning with a dot by default (e.g. `.profile`,
etc.)

While this is also the default behavior in shells, it's somewhat
inconvenient since there are many dotfiles in modern projects which are
still types of files under some other extension (e.g. `.rubocop.yml` is
a YAML file).

Change the default behavior of globs in Overcommit to match dotfiles by
default, as this is likely the desired behavior in most cases. Users can
always explicitly exclude dotfiles separately if they want to.

Change-Id: Id613d8b95bfb9a15ad2b9dbb2823e391d9823210
Reviewed-on: http://gerrit.causes.com/40420
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
Remove reference to FNM_EXTGLOB

Apparently this doesn't exist in JRuby. See:

https://github.com/jruby/jruby/issues/721

Change-Id: Idb9c80789dc98ba5b34b0b4c4e7cc132ff6a932a
Reviewed-on: http://gerrit.causes.com/40421
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
Remove unnecessary control flow code in HookRunner

We changed the code around in this file in c590b31 but accidentally left
this code in, which was unnecessary. Remove it.

Change-Id: I68c6db25d18f92e5b4b467b8d7031d09b6b00530
Reviewed-on: http://gerrit.causes.com/40458
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
Tested-by: jenkins <jenkins@causes.com>
Extract printing concern from HookRunner into helper

The `HookRunner` class was the largest class, and arguably one of the
most complicated.

An obvious separation of concerns was the flow of events versus the
printing of output to the user. A solution was to separate the printing
into a separate helper class which the `HookRunner` could just send
messages to when certain events occurred.

It's a bit crude since we're still passing a few parameters here and
there that should probably be encapsulated in separate objects, but this
already provides us some benefit in terms of reducing the size of the
class. We also should probably consider having the printer passed to the
`HookLoader` implementations as well, but right now things still work
and this is something that can be shipped.

Change-Id: I93c639b69e4d468ac1766cf86599c413d6c482eb
Reviewed-on: http://gerrit.causes.com/40459
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
Add Rubocop to Travis build

Now that the repo has no Rubocop warnings, we can ensure that no more
warnings sneak in by running Rubocop in Travis.

In the process, we pin the version of Rubocop used to 0.24.1, the latest
current version at the time of writing. This will prevent the build from
suddenly failing when a new version of the `rubocop` gem is released.

Change-Id: I831a5f576fa5b89194fcfd054ab8cebebc26fb3f
Reviewed-on: http://gerrit.causes.com/40460
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
Add Ruby 2.1.2 to Travis test matrix

Change-Id: I57e77b4dc7184bf67f13a0c8df5103be4947029c
Reviewed-on: http://gerrit.causes.com/40461
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
Add UTF8 encoding marker in Printer class

Since we moved the strings from `HookRunner` to `Printer`, we also need
to mark that file as UTF8 for older versions of Ruby.

In order to get the build to pass, also limit the RuboCop `Encoding`
check to only warn when needed, so that we don't get lots of warnings
under JRuby.

Change-Id: I1eec4710f73c542fa1959ea2a50b8495e96d273e
Reviewed-on: http://gerrit.causes.com/40462
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
Drop support for Ruby 1.8.7

The time has finally come. While Ruby 1.8.7 technically EOLed a while
ago, we were continuing to support it so users running older versions of
OS X operating systems (and many Linux distributions) would be able to
install it without doing anything.

This was a pain, but not too much hassle. However, a dependency for our
build infrastructure, RuboCop, depends on a gem that does not support
Ruby 1.8.7. It's not worth it for us to jump through hoops to continue
to support 1.8.7, so let's call it a good run and end it now.

At some point we'll follow up with converting all the 1.8 hashes to 1.9
syntax, and removing any other 1.8.7 hacks.

Change-Id: I9a048062bd905c685b8e5a633ca44af7cd1a7879
Reviewed-on: http://gerrit.causes.com/40470
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
Remove Ruby 1.8.7 from Travis build matrix

Change-Id: Idcb1414c0474163c9433f5d57d66ece26624c8c6
Reviewed-on: http://gerrit.causes.com/40471
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>