Class Grit::Submodule
In: lib/grit/submodule.rb
Parent: Object

Methods

Attributes

id  [R] 
mode  [R] 
name  [R] 

Public Class methods

The configuration information for the given repo

  +repo+ is the Repo
  +ref+ is the committish (defaults to 'master')

Returns a Hash of { <path:String> => { ‘url’ => <url:String>, ‘id’ => <id:String> } } Returns {} if no .gitmodules file was found

[Source]

    # File lib/grit/submodule.rb, line 52
52:     def self.config(repo, ref = "master")
53:       commit = repo.commit(ref)
54:       blob = commit.tree/'.gitmodules'
55:       return {} unless blob
56:       
57:       lines = blob.data.gsub(/\r\n?/, "\n" ).split("\n")
58:       
59:       config = {}
60:       current = nil
61:       
62:       lines.each do |line|
63:         if line =~ /^\[submodule "(.+)"\]$/
64:           current = $1
65:           config[current] = {}
66:           config[current]['id'] = (commit.tree/current).id
67:         elsif line =~ /^\t(\w+) = (.+)$/
68:           config[current][$1] = $2
69:           config[current]['id'] = (commit.tree/$2).id if $1 == 'path'
70:         else
71:           # ignore
72:         end
73:       end
74:       
75:       config
76:     end

Create a Submodule containing just the specified attributes

  +repo+ is the Repo
  +atts+ is a Hash of instance variable data

Returns Grit::Submodule (unbaked)

[Source]

    # File lib/grit/submodule.rb, line 13
13:     def self.create(repo, atts)
14:       self.allocate.create_initialize(repo, atts)
15:     end

Public Instance methods

[Source]

    # File lib/grit/submodule.rb, line 78
78:     def basename
79:       File.basename(name)
80:     end

Initializer for Submodule.create

  +repo+ is the Repo
  +atts+ is a Hash of instance variable data

Returns Grit::Submodule

[Source]

    # File lib/grit/submodule.rb, line 22
22:     def create_initialize(repo, atts)
23:       @repo = repo
24:       atts.each do |k, v|
25:         instance_variable_set("@#{k}".to_sym, v)
26:       end
27:       self
28:     end

Pretty object inspection

[Source]

    # File lib/grit/submodule.rb, line 83
83:     def inspect
84:       %Q{#<Grit::Submodule "#{@id}">}
85:     end

The url of this submodule

  +ref+ is the committish that should be used to look up the url

Returns String

[Source]

    # File lib/grit/submodule.rb, line 34
34:     def url(ref)
35:       config = self.class.config(@repo, ref)
36:       
37:       lookup = config.keys.inject({}) do |acc, key|
38:         id = config[key]['id']
39:         acc[id] = config[key]['url']
40:         acc
41:       end
42:       
43:       lookup[@id]
44:     end

[Validate]