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

Commit

Permalink
Merge pull request #723 from mssola/git-exists
Browse files Browse the repository at this point in the history
config/initializers: don't use mkmf
  • Loading branch information
mssola committed Feb 10, 2016
2 parents 9164632 + 644a8e3 commit 197d2bd
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 197d2bd

Please sign in to comment.