Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
config/initializers: don't use mkmf
Browse files Browse the repository at this point in the history
To determine whether "git" is on the system, we used the mkmf library. This has
turned out to not be the best option because then a "mkmf.log" file is always
generated.

Signed-off-by: Miquel Sabaté Solà <[email protected]>
  • Loading branch information
mssola committed May 6, 2016
1 parent c1fb8c3 commit fb5be5c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions config/initializers/version.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
require 'mkmf'

# Version module
# Makes the app version available to the application itself
# Needs the git executable for all git operations
module Version
git = find_executable('git')
BRANCH = git ? `git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3 2>/dev/null`.chomp : nil
COMMIT = git ? `git log --pretty=format:'%h' -n 1 2>/dev/null`.chomp : nil
TAG = git ? `git tag --points-at $(git rev-parse HEAD) 2>/dev/null`.chomp : nil

# Returns true if git is in the system, false otherwise.
def self.git?
paths = ENV["PATH"].split(":")
paths.each { |p| return true if File.executable?(File.join(p, "git")) }
false
end

BRANCH = Version.git? ? `git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3 2>/dev/null`.chomp : nil
COMMIT = Version.git? ? `git log --pretty=format:'%h' -n 1 2>/dev/null`.chomp : nil
TAG = Version.git? ? `git tag --points-at $(git rev-parse HEAD) 2>/dev/null`.chomp : nil

# Version.value returns the app version
# Priority: git tag > git branch/commit > VERSION file
def self.value
Expand Down

0 comments on commit fb5be5c

Please sign in to comment.