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, register_source, require_matched_dependency_version, #source_config, 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
43
# 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



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

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

#gitmodules_pathObject



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

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

#submodule_pathsObject



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

def submodule_paths
  @submodule_paths ||= {}
end