Class: Licensed::Sources::GitSubmodule

Inherits:
Source
  • Object
show all
Defined in:
lib/licensed/sources/git_submodule.rb

Constant Summary collapse

REMOTE_URL_ARGUMENT =
"$(git remote get-url origin)".freeze
GIT_SUBMODULES_ARGUMENTS =
[
  "$displaypath", # path from repo root to submodule folder to find the name and submodule content
  "$toplevel", # path to parent repository to calculate the ancestor chain
  "$sha1", # use the commit reference of the submodule as the version
  "$(git config --get remote.origin.url)", # use the configured remote origin url as the homepage
].freeze

Instance Attribute Summary

Attributes inherited from Source

#config

Instance Method Summary collapse

Methods inherited from Source

#dependencies, full_type, #ignored?, inherited, #initialize, type, type_and_version

Constructor Details

This class inherits a constructor from Licensed::Sources::Source

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


14
15
16
17
# File 'lib/licensed/sources/git_submodule.rb', line 14

def enabled?
  return false unless Licensed::Shell.tool_available?("git") && Licensed::Git.git_repo?
  gitmodules_path.exist?
end

#enumerate_dependenciesObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/licensed/sources/git_submodule.rb', line 19

def enumerate_dependencies
  git_submodules_command.lines.map do |line|
    displaypath, toplevel, version, homepage = line.strip.split
    name = File.basename(displaypath)
    submodule_path = if toplevel == config.pwd.to_s
      name
    else
      parent = File.basename(toplevel)
      "#{submodule_paths[parent]}/#{name}"
    end
    submodule_paths[name] = submodule_path

    Licensed::Dependency.new(
      name: submodule_path,
      version: version,
      path: config.pwd.join(displaypath),
      metadata: {
        "type" => self.class.type,
        "name" => name,
        "homepage" => homepage
      }
    )
  end
end

#git_submodules_commandObject



48
49
50
# File 'lib/licensed/sources/git_submodule.rb', line 48

def git_submodules_command
  Licensed::Shell.execute("git", "submodule", "foreach", "-q", "--recursive", "echo #{GIT_SUBMODULES_ARGUMENTS.join(" ")}")
end

#gitmodules_pathObject



52
53
54
# File 'lib/licensed/sources/git_submodule.rb', line 52

def gitmodules_path
  config.pwd.join(".gitmodules")
end

#submodule_pathsObject



44
45
46
# File 'lib/licensed/sources/git_submodule.rb', line 44

def submodule_paths
  @submodule_paths ||= {}
end