Class: Chandler::Git
- Inherits:
-
Object
- Object
- Chandler::Git
- Defined in:
- lib/chandler/git.rb
Overview
Uses the shell to execute git commands against a given .git directory.
Constant Summary collapse
- Error =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#tag_mapper ⇒ Object
readonly
Returns the value of attribute tag_mapper.
Instance Method Summary collapse
-
#initialize(path:, tag_mapper:) ⇒ Git
constructor
Initializes the Git object with the path to the ‘.git` directory of the desired git repository.
-
#origin_remote ⇒ Object
Uses ‘git remote -v` to list the remotes and returns the URL of the first one labeled “origin”.
-
#version_tags ⇒ Object
Uses ‘git tag -l` to obtain the list of tags, then returns the subset of those tags that appear to be version numbers.
Constructor Details
#initialize(path:, tag_mapper:) ⇒ Git
Initializes the Git object with the path to the ‘.git` directory of the desired git repository.
Chandler::Git.new(:path => “/path/to/my/project/.git”)
17 18 19 20 |
# File 'lib/chandler/git.rb', line 17 def initialize(path:, tag_mapper:) @path = path @tag_mapper = tag_mapper end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/chandler/git.rb', line 10 def path @path end |
#tag_mapper ⇒ Object (readonly)
Returns the value of attribute tag_mapper.
10 11 12 |
# File 'lib/chandler/git.rb', line 10 def tag_mapper @tag_mapper end |
Instance Method Details
#origin_remote ⇒ Object
Uses ‘git remote -v` to list the remotes and returns the URL of the first one labeled “origin”.
origin_remote # => “[email protected]:mattbrictson/chandler.git”
40 41 42 43 |
# File 'lib/chandler/git.rb', line 40 def origin_remote origin = git("remote", "-v").lines.grep(/^origin\s/).first origin && origin.split[1] end |
#version_tags ⇒ Object
Uses ‘git tag -l` to obtain the list of tags, then returns the subset of those tags that appear to be version numbers.
version_tags # => [“v0.0.1”, “v0.2.0”, “v0.2.1”, “v0.3.0”]
27 28 29 30 31 32 33 |
# File 'lib/chandler/git.rb', line 27 def = git("tag", "-l").lines.map(&:strip).select do |tag| version_part = tag_mapper.call(tag) version_part && version_part.version? end .sort_by { |t| Gem::Version.new(tag_mapper.call(t).version_number) } end |