Class: Groundskeeper::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/groundskeeper/repository.rb

Overview

A Git repository.

Constant Summary collapse

ON_BRANCH_MASTER =

git output matching

"On branch master"
UP_TO_DATE =
"Your branch is up-to-date with 'origin/master'"
UNSTAGED_CHANGES =
"Changes not staged for commit"
COMMIT_HASH =

git comment matching

/^[^ ]+ /
RELEASE_MESSAGE =
"release version %s"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(git: nil) ⇒ Repository



16
17
18
# File 'lib/groundskeeper/repository.rb', line 16

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

Instance Attribute Details

#gitObject (readonly)

Returns the value of attribute git.



14
15
16
# File 'lib/groundskeeper/repository.rb', line 14

def git
  @git
end

Instance Method Details

#bumped_semantic_version(type) ⇒ Object



51
52
53
# File 'lib/groundskeeper/repository.rb', line 51

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

#changes_since_latest_tagObject



44
45
46
47
48
49
# File 'lib/groundskeeper/repository.rb', line 44

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

#clean_directory?Boolean



20
21
22
# File 'lib/groundskeeper/repository.rb', line 20

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

#nameObject



55
56
57
# File 'lib/groundskeeper/repository.rb', line 55

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

#on_branch_master?Boolean



24
25
26
# File 'lib/groundskeeper/repository.rb', line 24

def on_branch_master?
  git.status.include? ON_BRANCH_MASTER
end

#statusObject



36
37
38
39
40
41
42
# File 'lib/groundskeeper/repository.rb', line 36

def status
  @status ||= begin
    git.fetch

    git.status
  end
end

#unstaged_changes?Boolean



32
33
34
# File 'lib/groundskeeper/repository.rb', line 32

def unstaged_changes?
  git.status.include? UNSTAGED_CHANGES
end

#up_to_date?Boolean



28
29
30
# File 'lib/groundskeeper/repository.rb', line 28

def up_to_date?
  git.status.include? UP_TO_DATE
end