Class: Groundskeeper::Git
- Inherits:
-
Object
- Object
- Groundskeeper::Git
- Defined in:
- lib/groundskeeper/git.rb
Overview
Wraps git executable and adds a few convenience methods on top.
Constant Summary collapse
- COMMAND =
"git"
- STATUS =
git arguments
"status"
- FETCH_WITH_TAGS =
"fetch --tags"
- VERSION =
"--version"
- TAGS_ASC =
"tag -l --sort=v:refname"
- TAGS_DESC =
"tag -l --sort=-v:refname"
- LATEST_TAG_COMMIT =
"#{COMMAND} rev-list --tags --max-count=1".freeze
- LATEST_TAG_NAME =
format("describe --tags $(%<commit>s)", commit: LATEST_TAG_COMMIT)
- LATEST_TAG_BRANCHES =
format("branch --contains $(%<commit>s)", commit: LATEST_TAG_COMMIT)
- LATEST_CHANGES =
"log %s..HEAD --oneline"
- CREATE_AND_CHECKOUT_BRANCH =
"checkout -b %s"
- ADD_UPDATE =
"add -u"
- ADD_ALL =
"add ."
- COMMIT =
"commit -m \"%s\""
- PUSH_HEAD =
"push origin head"
- PULL =
"-C #{Dir.home}/%s pull".freeze
- REMOTE_URL =
"-C #{Dir.home}/%s config --get remote.origin.url".freeze
- ORIGIN_URL =
"config --get remote.origin.url"
Instance Attribute Summary collapse
-
#git ⇒ Object
readonly
Returns the value of attribute git.
Class Method Summary collapse
Instance Method Summary collapse
- #add_all ⇒ Object
- #add_update ⇒ Object
- #branches_containing_latest_tag ⇒ Object
- #commit(message) ⇒ Object
- #create_and_checkout_branch(name) ⇒ Object
- #fetch ⇒ Object
- #fetch_and_list_tags ⇒ Object
-
#initialize(git) ⇒ Git
constructor
A new instance of Git.
- #latest_tag_name_across_branches ⇒ Object
- #list_tags ⇒ Object
- #origin_url ⇒ Object
- #pull(name) ⇒ Object
- #push ⇒ Object
- #raw_changes_since_latest_tag ⇒ Object
- #remote_url(name) ⇒ Object
- #status ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(git) ⇒ Git
Returns a new instance of Git.
34 35 36 |
# File 'lib/groundskeeper/git.rb', line 34 def initialize(git) @git = git end |
Instance Attribute Details
#git ⇒ Object (readonly)
Returns the value of attribute git.
28 29 30 |
# File 'lib/groundskeeper/git.rb', line 28 def git @git end |
Class Method Details
.build ⇒ Object
30 31 32 |
# File 'lib/groundskeeper/git.rb', line 30 def self.build new Executable.new(COMMAND) end |
Instance Method Details
#add_all ⇒ Object
83 84 85 |
# File 'lib/groundskeeper/git.rb', line 83 def add_all git.execute(ADD_ALL) end |
#add_update ⇒ Object
79 80 81 |
# File 'lib/groundskeeper/git.rb', line 79 def add_update git.execute(ADD_UPDATE) end |
#branches_containing_latest_tag ⇒ Object
65 66 67 |
# File 'lib/groundskeeper/git.rb', line 65 def branches_containing_latest_tag git.execute(LATEST_TAG_BRANCHES).split("\n").map(&:strip) end |
#commit(message) ⇒ Object
87 88 89 |
# File 'lib/groundskeeper/git.rb', line 87 def commit() git.execute(format(COMMIT, )) end |
#create_and_checkout_branch(name) ⇒ Object
75 76 77 |
# File 'lib/groundskeeper/git.rb', line 75 def create_and_checkout_branch(name) git.execute(format(CREATE_AND_CHECKOUT_BRANCH, name)) end |
#fetch ⇒ Object
42 43 44 |
# File 'lib/groundskeeper/git.rb', line 42 def fetch git.execute(FETCH_WITH_TAGS) end |
#fetch_and_list_tags ⇒ Object
56 57 58 59 |
# File 'lib/groundskeeper/git.rb', line 56 def git.execute(FETCH_WITH_TAGS) git.execute(TAGS_DESC).split("\n") end |
#latest_tag_name_across_branches ⇒ Object
61 62 63 |
# File 'lib/groundskeeper/git.rb', line 61 def latest_tag_name_across_branches git.execute(LATEST_TAG_NAME).chop end |
#list_tags ⇒ Object
52 53 54 |
# File 'lib/groundskeeper/git.rb', line 52 def git.execute(TAGS_ASC) end |
#origin_url ⇒ Object
103 104 105 |
# File 'lib/groundskeeper/git.rb', line 103 def origin_url git.execute(ORIGIN_URL).strip end |
#pull(name) ⇒ Object
95 96 97 |
# File 'lib/groundskeeper/git.rb', line 95 def pull(name) git.execute(format(PULL, name)) end |
#push ⇒ Object
91 92 93 |
# File 'lib/groundskeeper/git.rb', line 91 def push git.execute(PUSH_HEAD) end |
#raw_changes_since_latest_tag ⇒ Object
69 70 71 72 73 |
# File 'lib/groundskeeper/git.rb', line 69 def raw_changes_since_latest_tag latest_changes = format(LATEST_CHANGES, latest_tag_name_across_branches) git.execute(latest_changes).split("\n") end |
#remote_url(name) ⇒ Object
99 100 101 |
# File 'lib/groundskeeper/git.rb', line 99 def remote_url(name) git.execute(format(REMOTE_URL, name)) end |
#status ⇒ Object
38 39 40 |
# File 'lib/groundskeeper/git.rb', line 38 def status git.execute(STATUS) end |
#version ⇒ Object
46 47 48 49 50 |
# File 'lib/groundskeeper/git.rb', line 46 def version semantic_version = /\d+.\d+.\d+/ git.execute(VERSION).match(semantic_version)[0] end |