Sha256: ecffaaca0651e57a5b88b9535fbb8a0811f19b35b4a32a360f4aacea8302f809

Contents?: true

Size: 1.27 KB

Versions: 8

Compression:

Stored size: 1.27 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

    # :nocov:
    def status
      @status ||= begin
        git.fetch

        git.status
      end
    end
    # :nocov:

    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

8 entries across 8 versions & 1 rubygems

Version Path
groundskeeper-bitcore-0.34.0 lib/groundskeeper/repository.rb
groundskeeper-bitcore-0.33.0 lib/groundskeeper/repository.rb
groundskeeper-bitcore-0.32.0 lib/groundskeeper/repository.rb
groundskeeper-bitcore-0.31.0 lib/groundskeeper/repository.rb
groundskeeper-bitcore-0.29.0 lib/groundskeeper/repository.rb
groundskeeper-bitcore-0.28.0 lib/groundskeeper/repository.rb
groundskeeper-bitcore-0.27.0 lib/groundskeeper/repository.rb
groundskeeper-bitcore-0.26.0 lib/groundskeeper/repository.rb