Class: Duffy::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/duffy/git.rb

Overview

I like to have a git log in the admin section of my websites. I use these in my capistrano tasks to generate what I need and upload along with the deployment. If for some reason you don’t have git installed, each method returns nil.

Class Method Summary collapse

Class Method Details

.branchObject

Display the current branch



35
36
37
38
39
# File 'lib/duffy/git.rb', line 35

def branch
  `git rev-parse --abbrev-ref HEAD`.strip.presence
rescue
  nil
end

.countObject

I tend use the commit count / 1000.0 as a version for my applications. You wouldn’t want to do that if you’re building a gem used by others.



19
20
21
22
23
# File 'lib/duffy/git.rb', line 19

def count
  `git rev-list HEAD --count`.presence.to_i
rescue
  nil
end

.emailObject

Read the git committer’s email. Uses local if present, otherwise global (git default procedure) nil if unset



28
29
30
31
32
# File 'lib/duffy/git.rb', line 28

def email
  `git config --get user.email`.strip.presence
rescue
  nil
end

.logObject

Produce tab separated listing of current git log. Useful for displaying a development history page.



11
12
13
14
15
# File 'lib/duffy/git.rb', line 11

def log
  `git log --pretty=format:"%ad%x09%an%x09%s" --date=short`.strip.presence
rescue
  nil
end