Sha256: c588b8ba3771d014744a4808af174ac3f8766ab049a2448614fa25ef0554c580

Contents?: true

Size: 1.27 KB

Versions: 5

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

5 entries across 5 versions & 1 rubygems

Version Path
groundskeeper-bitcore-0.24.0 lib/groundskeeper/repository.rb
groundskeeper-bitcore-0.23.0 lib/groundskeeper/repository.rb
groundskeeper-bitcore-0.3.4 lib/groundskeeper/repository.rb
groundskeeper-bitcore-0.3.3 lib/groundskeeper/repository.rb
groundskeeper-bitcore-0.3.2 lib/groundskeeper/repository.rb