Sha256: ecff56ea3227e68a98907616f1d9fa102a547a1720d060bc51af57d7ac6cbfdd

Contents?: true

Size: 750 Bytes

Versions: 32

Compression:

Stored size: 750 Bytes

Contents

# frozen_string_literal: true

module CiToolkit
  # Utility class to provide information about git related data
  class Git
    def initialize(dir = nil, env = CiToolkit::BitriseEnv.new)
      @branch = env.git_branch
      @dir = dir
    end

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

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

    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

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

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
ci_toolkit-1.5.8 lib/ci_toolkit/git.rb
ci_toolkit-1.5.7 lib/ci_toolkit/git.rb
ci_toolkit-1.5.6 lib/ci_toolkit/git.rb
ci_toolkit-1.5.5 lib/ci_toolkit/git.rb
ci_toolkit-1.5.4 lib/ci_toolkit/git.rb
ci_toolkit-1.5.3 lib/ci_toolkit/git.rb
ci_toolkit-1.5.2 lib/ci_toolkit/git.rb
ci_toolkit-1.5.1 lib/ci_toolkit/git.rb
ci_toolkit-1.5.0 lib/ci_toolkit/git.rb
ci_toolkit-1.4.13 lib/ci_toolkit/git.rb
ci_toolkit-1.4.12 lib/ci_toolkit/git.rb
ci_toolkit-1.4.11 lib/ci_toolkit/git.rb