Class: Remotes::Refspec
- Inherits:
-
Struct
- Object
- Struct
- Remotes::Refspec
- Defined in:
- lib/remotes/refspec.rb
Instance Attribute Summary collapse
-
#forced ⇒ Object
Returns the value of attribute forced.
-
#source ⇒ Object
Returns the value of attribute source.
-
#target ⇒ Object
Returns the value of attribute target.
Class Method Summary collapse
- .canonical(name) ⇒ Object
- .expand(specs, refs) ⇒ Object
- .invert(specs, ref) ⇒ Object
- .parse(spec) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#forced ⇒ Object
Returns the value of attribute forced
10 11 12 |
# File 'lib/remotes/refspec.rb', line 10 def forced @forced end |
#source ⇒ Object
Returns the value of attribute source
10 11 12 |
# File 'lib/remotes/refspec.rb', line 10 def source @source end |
#target ⇒ Object
Returns the value of attribute target
10 11 12 |
# File 'lib/remotes/refspec.rb', line 10 def target @target end |
Class Method Details
.canonical(name) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/remotes/refspec.rb', line 19 def self.canonical(name) return nil if name.to_s == "" return name unless Revision.valid_ref?(name) first = Pathname.new(name).descend.first dirs = [Refs::REFS_DIR, Refs::HEADS_DIR, Refs::REMOTES_DIR] prefix = dirs.find { |dir| dir.basename == first } (prefix&.dirname || Refs::HEADS_DIR).join(name).to_s end |
.expand(specs, refs) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/remotes/refspec.rb', line 30 def self.(specs, refs) specs = specs.map { |spec| Refspec.parse(spec) } specs.reduce({}) do |mappings, spec| mappings.merge(spec.match_refs(refs)) end end |
.invert(specs, ref) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/remotes/refspec.rb', line 38 def self.invert(specs, ref) specs = specs.map { |spec| Refspec.parse(spec) } map = specs.reduce({}) do |mappings, spec| spec.source, spec.target = spec.target, spec.source mappings.merge(spec.match_refs([ref])) end map.keys.first end |
Instance Method Details
#match_refs(refs) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/remotes/refspec.rb', line 49 def match_refs(refs) return { target => [source, forced] } unless source.to_s.include?("*") pattern = /^#{ source.sub("*", "(.*)") }$/ mappings = {} refs.each do |ref| next unless match = pattern.match(ref) dst = match[1] ? target.sub("*", match[1]) : target mappings[dst] = [ref, forced] end mappings end |
#to_s ⇒ Object
64 65 66 67 |
# File 'lib/remotes/refspec.rb', line 64 def to_s spec = forced ? "+" : "" spec + [source, target].join(":") end |