Class: CiToolkit::Git

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

Overview

Utility class to provide information about git related data

Instance Method Summary collapse

Constructor Details

#initialize(dir = nil, env = CiToolkit::BitriseEnv.new) ⇒ Git

Returns a new instance of Git.



6
7
8
9
# File 'lib/ci_toolkit/git.rb', line 6

def initialize(dir = nil, env = CiToolkit::BitriseEnv.new)
  @branch = env.git_branch
  @dir = dir
end

Instance Method Details

#branchObject



18
19
20
21
22
23
24
25
# File 'lib/ci_toolkit/git.rb', line 18

def branch
  return @branch unless @branch.nil?

  git_branch_cmd = "git branch --show-current"
  return `cd #{@dir} && #{git_branch_cmd}`.gsub(/\s+/, "") unless @dir.nil?

  `#{git_branch_cmd}`.gsub(/\s+/, "")
end

#infrastructure_branch?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/ci_toolkit/git.rb', line 27

def infrastructure_branch?
  !(branch =~ %r{infra/}).nil?
end

#latest_tagObject



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

def latest_tag
  describe = "git describe --tags --abbrev=0"
  return `#{describe}`.gsub("\n", "") unless @dir

  `cd #{@dir} && #{describe}`.gsub("\n", "")
end