self.config

in lib/grit/submodule.rb [51:81]


    def self.config(repo, ref = "master")
      commit = repo.commit(ref)
      blob = commit.tree/'.gitmodules'
      return {} unless blob

      lines = blob.data.gsub(/\r\n?/, "\n" ).split("\n")

      config = {}
      current = nil

      lines.each do |line|
        if line =~ /^\[submodule "(.+)"\]$/
          current = $1
          config[current] = {}
          submodule = (commit.tree/current.strip)
          config[current]['id'] = submodule.id if submodule
        elsif line =~ /^\t(\w+) = (.+)$/
          config[current][$1] = $2

          if $1 == 'path'
            submodule = (commit.tree/$2.strip)
            config[current]['id'] = submodule.id if submodule
          end
        else
          
        end
      end

      config
    end