Class: Groundskeeper::Repository
- Inherits:
-
Object
- Object
- Groundskeeper::Repository
- 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
-
#git ⇒ Object
readonly
Returns the value of attribute git.
Instance Method Summary collapse
- #bumped_semantic_version(type) ⇒ Object
-
#changes_since_latest_tag ⇒ Object
:nocov:.
- #clean_directory? ⇒ Boolean
-
#initialize(git: nil) ⇒ Repository
constructor
A new instance of Repository.
- #name ⇒ Object
- #on_branch_master? ⇒ Boolean
-
#status ⇒ Object
:nocov:.
- #unstaged_changes? ⇒ Boolean
- #up_to_date? ⇒ Boolean
Constructor Details
#initialize(git: nil) ⇒ Repository
Returns a new instance of Repository.
16 17 18 |
# File 'lib/groundskeeper/repository.rb', line 16 def initialize(git: nil) @git = git || Git.build end |
Instance Attribute Details
#git ⇒ Object (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
53 54 55 |
# File 'lib/groundskeeper/repository.rb', line 53 def bumped_semantic_version(type) SemanticVersion.new(git.latest_tag_name_across_branches).bump(type) end |
#changes_since_latest_tag ⇒ Object
:nocov:
46 47 48 49 50 51 |
# File 'lib/groundskeeper/repository.rb', line 46 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 |
#name ⇒ Object
57 58 59 |
# File 'lib/groundskeeper/repository.rb', line 57 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 |
#status ⇒ Object
:nocov:
37 38 39 40 41 42 43 |
# File 'lib/groundskeeper/repository.rb', line 37 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 |