Class: Lolcommits::MercurialInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/lolcommits/backends/mercurial_info.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMercurialInfo

Returns a new instance of MercurialInfo.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/lolcommits/backends/mercurial_info.rb', line 11

def initialize
  # mercurial sets HG_RESULT for post- hooks
  if ENV.key?("HG_RESULT") && ENV["HG_RESULT"] != "0"
    debug "Aborting lolcommits hook from failed operation"
    exit 1
  end

  Mercurial.configure do |conf|
    conf.hg_binary_path = "hg"
  end
  debug "parsed the following values from commit:"
  debug "\t#{message}"
  debug "\t#{sha}"
  debug "\t#{repo_internal_path}"
  debug "\t#{repo}"
  debug "\t#{branch}"
  debug "\t#{commit_date}"
  debug "\t#{author_name}" if author_name
  debug "\t#{author_email}" if author_email
end

Class Method Details

.local_name(path = ".") ⇒ Object



7
8
9
# File 'lib/lolcommits/backends/mercurial_info.rb', line 7

def self.local_name(path = ".")
  File.basename(File.dirname(Mercurial::Repository.open(path).dothg_path))
end

.repo_root?(path = ".") ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/lolcommits/backends/mercurial_info.rb', line 3

def self.repo_root?(path = ".")
  File.directory?(File.join(path, ".hg"))
end

Instance Method Details

#author_emailObject



63
64
65
# File 'lib/lolcommits/backends/mercurial_info.rb', line 63

def author_email
  @author_email ||= last_commit.author_email
end

#author_nameObject



59
60
61
# File 'lib/lolcommits/backends/mercurial_info.rb', line 59

def author_name
  @author_name ||= last_commit.author
end

#branchObject



32
33
34
# File 'lib/lolcommits/backends/mercurial_info.rb', line 32

def branch
  @branch ||= last_commit.branch_name
end

#commit_dateObject



67
68
69
# File 'lib/lolcommits/backends/mercurial_info.rb', line 67

def commit_date
  @commit_date ||= last_commit.date.utc
end

#messageObject



36
37
38
39
40
41
# File 'lib/lolcommits/backends/mercurial_info.rb', line 36

def message
  @message ||= begin
    message = last_commit.message || ""
    message.split("\n").first
  end
end

#repoObject



55
56
57
# File 'lib/lolcommits/backends/mercurial_info.rb', line 55

def repo
  @repo ||= File.basename(File.dirname(repo_internal_path))
end

#repo_internal_pathObject



47
48
49
# File 'lib/lolcommits/backends/mercurial_info.rb', line 47

def repo_internal_path
  @repo_internal_path ||= repository.dothg_path
end

#shaObject



43
44
45
# File 'lib/lolcommits/backends/mercurial_info.rb', line 43

def sha
  @sha ||= last_commit.id[0..10]
end

#urlObject



51
52
53
# File 'lib/lolcommits/backends/mercurial_info.rb', line 51

def url
  @url ||= repository.path
end