Sha256: aadfc20ade48281abc37277c83494a25de9d8f666cc726010700283c2d444834

Contents?: true

Size: 1.24 KB

Versions: 9

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module Groundskeeper
  # A Git repository.
  class Repository
    # git output matching
    ON_BRANCH_MASTER = "On branch master"
    UP_TO_DATE = "Your branch is up-to-date with 'origin/master'"
    UNSTAGED_CHANGES = "Changes not staged for commit"
    # git comment matching
    COMMIT_HASH = /^[^ ]+ /
    RELEASE_MESSAGE = "release version %s"

    attr_reader :git

    def initialize(git: nil)
      @git = git || Git.build
    end

    def clean_directory?
      on_branch_master? && up_to_date? && !unstaged_changes?
    end

    def on_branch_master?
      git.status.include? ON_BRANCH_MASTER
    end

    def up_to_date?
      git.status.include? UP_TO_DATE
    end

    def unstaged_changes?
      git.status.include? UNSTAGED_CHANGES
    end

    def status
      @status ||= begin
        git.fetch

        git.status
      end
    end

    def changes_since_latest_tag
      git
        .raw_changes_since_latest_tag
        .map { |c| c.gsub(COMMIT_HASH, "") }
        .reject { |c| c.match(/#{format(RELEASE_MESSAGE, "")}/) }
    end

    def bumped_semantic_version(type)
      SemanticVersion.new(git.latest_tag_name_across_branches).bump(type)
    end

    def name
      `pwd`.split("/").last.chop
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
groundskeeper-bitcore-0.3.1 lib/groundskeeper/repository.rb
groundskeeper-bitcore-0.3.0 lib/groundskeeper/repository.rb
groundskeeper-bitcore-0.2.7 lib/groundskeeper/repository.rb
groundskeeper-bitcore-0.2.6 lib/groundskeeper/repository.rb
groundskeeper-bitcore-0.2.5 lib/groundskeeper/repository.rb
groundskeeper-bitcore-0.2.4 lib/groundskeeper/repository.rb
groundskeeper-bitcore-0.2.3 lib/groundskeeper/repository.rb
groundskeeper-bitcore-0.2.2 lib/groundskeeper/repository.rb
groundskeeper-bitcore-0.2.1 lib/groundskeeper/repository.rb