Class: GitUtils
- Inherits:
-
Object
- Object
- GitUtils
- Defined in:
- lib/git_utils.rb
Class Method Summary collapse
- .full_version ⇒ Object
- .git_branch ⇒ Object
- .git_version ⇒ Object
- .last_commit_date ⇒ Object
- .try_git(git_cmd, default_value) ⇒ Object
Class Method Details
.full_version ⇒ Object
13 14 15 |
# File 'lib/git_utils.rb', line 13 def self.full_version self.try_git('git describe --dirty --match "v[0-9]*" 2> /dev/null', "unknown") end |
.git_branch ⇒ Object
8 9 10 11 |
# File 'lib/git_utils.rb', line 8 def self.git_branch self.try_git("git branch --show-current", nil) || self.try_git("git config user.discourse-version", "unknown") end |
.git_version ⇒ Object
4 5 6 |
# File 'lib/git_utils.rb', line 4 def self.git_version self.try_git("git rev-parse HEAD", "unknown") end |
.last_commit_date ⇒ Object
17 18 19 20 21 |
# File 'lib/git_utils.rb', line 17 def self.last_commit_date git_cmd = 'git log -1 --format="%ct"' seconds = self.try_git(git_cmd, nil) seconds.nil? ? nil : DateTime.strptime(seconds, "%s") end |
.try_git(git_cmd, default_value) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/git_utils.rb', line 23 def self.try_git(git_cmd, default_value) value = begin `#{git_cmd}`.strip rescue StandardError default_value end (!value.empty? ? value : nil) || default_value end |