Class: Vanagon::Component::Source::Git
- Inherits:
-
Object
- Object
- Vanagon::Component::Source::Git
- Defined in:
- lib/vanagon/component/source/git.rb
Instance Attribute Summary collapse
-
#clone_options ⇒ Object
Returns the value of attribute clone_options.
-
#log_url ⇒ Object
Returns the value of attribute log_url.
-
#ref ⇒ Object
Returns the value of attribute ref.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#url ⇒ Object
Returns the value of attribute url.
-
#version ⇒ Object
readonly
Use ‘git describe` to lazy-load a version for this component.
-
#workdir ⇒ Object
Returns the value of attribute workdir.
Class Method Summary collapse
-
.valid_remote?(url, timeout = 0) ⇒ Boolean
def valid_remote?(url, timeout = 0) Timeout.timeout(timeout) do !!::Git.ls_remote(url) end rescue ::Git::GitExecuteError false rescue Timeout::Error false end.
Instance Method Summary collapse
-
#cleanup ⇒ String
Return the correct incantation to cleanup the source directory for a given source.
-
#clone ⇒ Object
Perform a git clone of @url as a lazy-loaded accessor for @clone.
-
#dirname ⇒ String
The dirname to reference when building from the repo.
-
#fetch ⇒ Object
Fetch the source.
-
#initialize(url, workdir:, **options) ⇒ Git
constructor
Constructor for the Git source type.
-
#verify ⇒ Object
There is no md5 to manually verify here, so this is a noop.
Constructor Details
#initialize(url, workdir:, **options) ⇒ Git
Constructor for the Git source type
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/vanagon/component/source/git.rb', line 76 def initialize(url, workdir:, **) # rubocop:disable Metrics/AbcSize opts = .merge(.reject { |k, v| v.nil? }) # Ensure that #url returns a URI object @url = URI.parse(url.to_s) @log_url = @url.host + @url.path unless @url.host.nil? || @url.path.nil? @ref = opts[:ref] @dirname = opts[:dirname] @workdir = File.realpath(workdir) @clone_options = opts[:clone_options] ||= {} # We can test for Repo existence without cloning raise Vanagon::InvalidRepo, "url is not a valid Git repo" unless valid_remote? end |
Instance Attribute Details
#clone_options ⇒ Object
Returns the value of attribute clone_options.
16 17 18 |
# File 'lib/vanagon/component/source/git.rb', line 16 def @clone_options end |
#log_url ⇒ Object
Returns the value of attribute log_url.
16 17 18 |
# File 'lib/vanagon/component/source/git.rb', line 16 def log_url @log_url end |
#ref ⇒ Object
Returns the value of attribute ref.
16 17 18 |
# File 'lib/vanagon/component/source/git.rb', line 16 def ref @ref end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
17 18 19 |
# File 'lib/vanagon/component/source/git.rb', line 17 def repo @repo end |
#url ⇒ Object
Returns the value of attribute url.
16 17 18 |
# File 'lib/vanagon/component/source/git.rb', line 16 def url @url end |
#version ⇒ Object (readonly)
Use ‘git describe` to lazy-load a version for this component
122 123 124 |
# File 'lib/vanagon/component/source/git.rb', line 122 def version @version end |
#workdir ⇒ Object
Returns the value of attribute workdir.
16 17 18 |
# File 'lib/vanagon/component/source/git.rb', line 16 def workdir @workdir end |
Class Method Details
.valid_remote?(url, timeout = 0) ⇒ Boolean
def valid_remote?(url, timeout = 0)
Timeout.timeout(timeout) do
!!::Git.ls_remote(url)
end
rescue ::Git::GitExecuteError
false
rescue Timeout::Error
false
end
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/vanagon/component/source/git.rb', line 51 def valid_remote?(url, timeout = 0) Timeout.timeout(timeout) do Vanagon::Utilities.local_command("git ls-remote --heads #{url} > /dev/null 2>&1") return false unless $?.exitstatus.zero? return true end rescue Timeout::Error return false rescue RuntimeError return false end |
Instance Method Details
#cleanup ⇒ String
Return the correct incantation to cleanup the source directory for a given source
104 105 106 |
# File 'lib/vanagon/component/source/git.rb', line 104 def cleanup "rm -rf #{dirname}" end |
#clone ⇒ Object
Perform a git clone of @url as a lazy-loaded accessor for @clone
128 129 130 131 132 133 134 |
# File 'lib/vanagon/component/source/git.rb', line 128 def clone if @clone_options.empty? @clone ||= ::Git.clone(url, dirname, path: workdir) else @clone ||= ::Git.clone(url, dirname, path: workdir, **) end end |
#dirname ⇒ String
The dirname to reference when building from the repo
117 118 119 |
# File 'lib/vanagon/component/source/git.rb', line 117 def dirname @dirname || File.basename(url.path, ".git") end |
#fetch ⇒ Object
Fetch the source. In this case, clone the repository into the workdir and check out the ref. Also sets the version if there is a git tag as a side effect.
94 95 96 97 98 99 |
# File 'lib/vanagon/component/source/git.rb', line 94 def fetch clone! checkout! version update_submodules end |
#verify ⇒ Object
There is no md5 to manually verify here, so this is a noop.
109 110 111 112 |
# File 'lib/vanagon/component/source/git.rb', line 109 def verify # nothing to do here, so just tell users that and return VanagonLogger.info "Nothing to verify for '#{dirname}' (using Git reference '#{ref}')" end |