Class: Changelogger::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/changelogger/repo_info.rb

Overview

Changelogger::Repo reads basic repository info for display.

Class Method Summary collapse

Class Method Details

.infoRepoInfo

Changelogger::Repo.info -> Changelogger::RepoInfo

Reads repo root, branch, HEAD short sha, origin url, and dirty flag.

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/changelogger/repo_info.rb', line 29

def info
  path = cmd('git rev-parse --show-toplevel').strip
  name = path.empty? ? File.basename(Dir.pwd) : File.basename(path)
  branch = cmd('git rev-parse --abbrev-ref HEAD').strip
  branch = '(detached)' if branch.empty? || branch == 'HEAD'
  head_short = cmd('git rev-parse --short HEAD').strip
  remote = cmd('git config --get remote.origin.url').strip
  dirty = !cmd('git status --porcelain').strip.empty?

  RepoInfo.new(
    name: name,
    path: path.empty? ? Dir.pwd : path,
    branch: branch,
    head_short: head_short,
    remote: remote,
    remote_slug: to_slug(remote),
    dirty: dirty
  )
end