Skip to content

Commit 40384fc

Browse files
committed
Add GIT_VERSION magic constant
Add a constant which makes it convenient to execute code based on the version of git we're running. Returning the `Overcommit::Utils::Version` class, doing a comparison is now as simple as writing: if GIT_VERSION < '1.8.5' ... end
1 parent b5e6c0e commit 40384fc

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/overcommit.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
require 'overcommit/constants'
22
require 'overcommit/exceptions'
3+
require 'overcommit/utils'
4+
require 'overcommit/git_version'
35
require 'overcommit/configuration_validator'
46
require 'overcommit/configuration'
57
require 'overcommit/configuration_loader'
@@ -16,5 +18,4 @@
1618
require 'overcommit/hook_runner'
1719
require 'overcommit/installer'
1820
require 'overcommit/logger'
19-
require 'overcommit/utils'
2021
require 'overcommit/version'

lib/overcommit/git_version.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Returns the version of the available git binary.
2+
#
3+
# This is intended to be used to conveniently execute code based on a specific
4+
# git version. Simply compare to a version string:
5+
#
6+
# @example
7+
# if GIT_VERSION <= '1.8.5'
8+
# ...
9+
# end
10+
module Overcommit
11+
GIT_VERSION = begin
12+
version = `git --version`.chomp[/[\d\.]+/, 0]
13+
Overcommit::Utils::Version.new(version)
14+
end
15+
end

0 commit comments

Comments
 (0)