Class: Groundskeeper::Git

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

Overview

Wraps git executable and adds a few convenience methods on top.

Defined Under Namespace

Classes: Executable

Constant Summary collapse

COMMAND =
"git"
STATUS =

git arguments

"status"
FETCH_WITH_TAGS =
"fetch --tags"
VERSION =
"--version"
TAGS_ASC =
"tag -l --sort=v:refname"
LATEST_TAG_COMMIT =
"#{COMMAND} rev-list --tags --max-count=1"
LATEST_TAG_NAME =
format("describe --tags $(%s)", LATEST_TAG_COMMIT)
LATEST_TAG_BRANCHES =
format("branch --contains $(%s)", LATEST_TAG_COMMIT)
LATEST_CHANGES =
"log %s..HEAD --oneline"
CREATE_AND_CHECKOUT_BRANCH =
"checkout -b %s"
ADD_UPDATE =
"add -u"
COMMIT =
"commit -m \"%s\""
ADD_TAG =
"tag %s"
PUSH_HEAD_WITH_TAGS =
"push origin head --tags"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(git) ⇒ Git

Returns a new instance of Git.



35
36
37
# File 'lib/groundskeeper/git.rb', line 35

def initialize(git)
  @git = git
end

Instance Attribute Details

#git ⇒ Object (readonly)

Returns the value of attribute git.



22
23
24
# File 'lib/groundskeeper/git.rb', line 22

def git
  @git
end

Class Method Details

.build ⇒ Object



31
32
33
# File 'lib/groundskeeper/git.rb', line 31

def self.build
  new Executable.new
end

Instance Method Details

#add_tag(name) ⇒ Object



83
84
85
# File 'lib/groundskeeper/git.rb', line 83

def add_tag(name)
  git.execute(format(ADD_TAG, name))
end

#add_update ⇒ Object



75
76
77
# File 'lib/groundskeeper/git.rb', line 75

def add_update
  git.execute(ADD_UPDATE)
end

#branches_containing_latest_tag ⇒ Object



61
62
63
# File 'lib/groundskeeper/git.rb', line 61

def branches_containing_latest_tag
  git.execute(LATEST_TAG_BRANCHES).split("\n").map(&:strip)
end

#commit(message) ⇒ Object



79
80
81
# File 'lib/groundskeeper/git.rb', line 79

def commit(message)
  git.execute(format(COMMIT, message))
end

#create_and_checkout_branch(name) ⇒ Object



71
72
73
# File 'lib/groundskeeper/git.rb', line 71

def create_and_checkout_branch(name)
  git.execute(format(CREATE_AND_CHECKOUT_BRANCH, name))
end

#fetch ⇒ Object



43
44
45
# File 'lib/groundskeeper/git.rb', line 43

def fetch
  git.execute(FETCH_WITH_TAGS)
end

#latest_tag_name_across_branches ⇒ Object



57
58
59
# File 'lib/groundskeeper/git.rb', line 57

def latest_tag_name_across_branches
  git.execute(LATEST_TAG_NAME).chop
end

#list_tags ⇒ Object



53
54
55
# File 'lib/groundskeeper/git.rb', line 53

def list_tags
  git.execute(TAGS_ASC)
end

#push_with_tags ⇒ Object



87
88
89
# File 'lib/groundskeeper/git.rb', line 87

def push_with_tags
  git.execute(PUSH_HEAD_WITH_TAGS)
end

#raw_changes_since_latest_tag ⇒ Object



65
66
67
68
69
# File 'lib/groundskeeper/git.rb', line 65

def raw_changes_since_latest_tag
  latest_changes = format(LATEST_CHANGES, latest_tag_name_across_branches)

  git.execute(latest_changes).split("\n")
end

#status ⇒ Object



39
40
41
# File 'lib/groundskeeper/git.rb', line 39

def status
  git.execute(STATUS)
end

#version ⇒ Object



47
48
49
50
51
# File 'lib/groundskeeper/git.rb', line 47

def version
  semantic_version = /\d+.\d+.\d+/

  git.execute(VERSION).match(semantic_version)[0]
end