Class: Plus2GitTagger::Git
- Inherits:
-
Struct
- Object
- Struct
- Plus2GitTagger::Git
- Defined in:
- lib/plus2_git_tagger/git.rb
Instance Attribute Summary collapse
-
#repo ⇒ Object
Returns the value of attribute repo.
Instance Method Summary collapse
-
#commit_if_required(subject) ⇒ Object
Try to commit, but don’t worry if it doesn’t work because it wasn’t needed.
-
#current_subject ⇒ Object
Queries git for HEAD’s subject.
-
#escaped_current_subject ⇒ Object
Naive: remove quotes.
-
#git(cmd) ⇒ Object
(also: #run)
Run git.
-
#git_s(cmd) ⇒ Object
Run git, capture stdout.
-
#initialize ⇒ Git
constructor
A new instance of Git.
-
#tags ⇒ Object
Returns a list of all tags for this repo.
Constructor Details
#initialize ⇒ Git
Returns a new instance of Git.
3 4 5 6 |
# File 'lib/plus2_git_tagger/git.rb', line 3 def initialize(*) super self.repo = Pathname( repo ). end |
Instance Attribute Details
#repo ⇒ Object
Returns the value of attribute repo
2 3 4 |
# File 'lib/plus2_git_tagger/git.rb', line 2 def repo @repo end |
Instance Method Details
#commit_if_required(subject) ⇒ Object
Try to commit, but don’t worry if it doesn’t work because it wasn’t needed.
24 25 26 27 28 29 30 |
# File 'lib/plus2_git_tagger/git.rb', line 24 def commit_if_required(subject) result = git_s("commit -uno -m '#{ subject }' 2>&1") unless $?.success? || result[/nothing to commit/i] || result[/no changes added to commit/i] abort result end end |
#current_subject ⇒ Object
Queries git for HEAD’s subject.
Returns a string containing HEAD’s subject.
12 13 14 |
# File 'lib/plus2_git_tagger/git.rb', line 12 def current_subject git_s('log --pretty="format:%s" -1').chomp end |
#escaped_current_subject ⇒ Object
Naive: remove quotes.
18 19 20 |
# File 'lib/plus2_git_tagger/git.rb', line 18 def escaped_current_subject current_subject.gsub(/["']/, '') end |
#git(cmd) ⇒ Object Also known as: run
Run git.
40 41 42 43 44 45 46 |
# File 'lib/plus2_git_tagger/git.rb', line 40 def git( cmd ) Dir.chdir( repo ) do system "git #{cmd}" abort("'git #{cmd}' failed") unless $?.success? end end |
#git_s(cmd) ⇒ Object
Run git, capture stdout.
51 52 53 54 55 |
# File 'lib/plus2_git_tagger/git.rb', line 51 def git_s( cmd ) Dir.chdir( repo ) do `git #{cmd}` end end |
#tags ⇒ Object
Returns a list of all tags for this repo.
34 35 36 |
# File 'lib/plus2_git_tagger/git.rb', line 34 def git_s('show-ref --tags --abbrev=1').split("\n").map {|line| line.split(/\s/).last.chomp.sub(%r[^refs/tags/],'')} end |