File version-git.patch of Package portus.2625
From f61fb4ec2e942537a8c00b7865bbdd37e3f009f2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miquel=20Sabat=C3=A9=20Sol=C3=A0?= <msabate@suse.com>
Date: Thu, 16 Jun 2016 16:38:49 +0200
Subject: [PATCH] version: don't rely on the `.git` directory
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
It does not make sense to try to fetch the version from git if the deployer has
removed the `.git` directory too.
Fixes #936
Signed-off-by: Miquel Sabaté Solà <msabate@suse.com>
---
config/initializers/version.rb | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/config/initializers/version.rb b/config/initializers/version.rb
index cb42d98..ee6ab7b 100644
--- a/config/initializers/version.rb
+++ b/config/initializers/version.rb
@@ -2,8 +2,13 @@
# Makes the app version available to the application itself
# Needs the git executable for all git operations
module Version
- # Returns true if git is in the system, false otherwise.
+ # Returns true if the version can be extracted by using git, false
+ # otherwise.
def self.git?
+ # Check that the ".git" directory at least exists.
+ return false unless File.exists?(Rails.root.join(".git"))
+
+ # Check whether we have git in our system.
paths = ENV["PATH"].split(":")
paths.each { |p| return true if File.executable?(File.join(p, "git")) }
false