Class: Geordi::Git

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

Class Method Summary collapse

Class Method Details

.commits_between(source, target) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/geordi/git.rb', line 44

def commits_between(source, target)
  return [ENV['GEORDI_TESTING_GIT_COMMIT']] if Util.testing?

  commits = `git --no-pager log --pretty=format:%s #{source}..#{target}`

  commits&.split("\n")
end

.current_branchObject



16
17
18
19
20
21
22
# File 'lib/geordi/git.rb', line 16

def current_branch
  if Util.testing?
    default_branch
  else
    `git rev-parse --abbrev-ref HEAD`.strip
  end
end

.default_branchObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/geordi/git.rb', line 33

def default_branch
  default_branch = if Util.testing?
    ENV['GEORDI_TESTING_DEFAULT_BRANCH']
  else
    head_symref = `git ls-remote --symref origin HEAD`
    head_symref[%r{\Aref: refs/heads/(\S+)\sHEAD}, 1]
  end

  default_branch || 'master'
end

.local_branch_namesObject



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/geordi/git.rb', line 4

def local_branch_names
  @local_branch_names ||= begin
    branch_list_string = if Util.testing?
      ENV['GEORDI_TESTING_GIT_BRANCHES'].to_s
    else
      `git branch --format="%(refname:short)"`
    end

    branch_list_string.strip.split("\n")
  end
end

.staged_changes?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
# File 'lib/geordi/git.rb', line 24

def staged_changes?
  if Util.testing?
    ENV['GEORDI_TESTING_STAGED_CHANGES'] == 'true'
  else
    statuses = `git status --porcelain`.split("\n")
    statuses.any? { |l| /^[A-Z]/i =~ l }
  end
end