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.
-
#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
Attempt to connect to whatever URL is provided and return True or False depending on whether or not ‘git` thinks it’s a valid Git repo.
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
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/vanagon/component/source/git.rb', line 51 def initialize(url, workdir:, **) opts = .merge(.reject { |k, v| v.nil? }) # Ensure that #url returns a URI object @url = URI.parse(url.to_s) @ref = opts[:ref] @workdir = File.realpath(workdir) @clone_options = opts[:clone_options] ||= {} # We can test for Repo existence without cloning raise Vanagon::InvalidRepo, "#{url} not a valid Git repo" unless valid_remote? end |
Instance Attribute Details
#clone_options ⇒ Object
Returns the value of attribute clone_options.
15 16 17 |
# File 'lib/vanagon/component/source/git.rb', line 15 def @clone_options end |
#ref ⇒ Object
Returns the value of attribute ref.
15 16 17 |
# File 'lib/vanagon/component/source/git.rb', line 15 def ref @ref end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
16 17 18 |
# File 'lib/vanagon/component/source/git.rb', line 16 def repo @repo end |
#url ⇒ Object
Returns the value of attribute url.
15 16 17 |
# File 'lib/vanagon/component/source/git.rb', line 15 def url @url end |
#version ⇒ Object (readonly)
Use ‘git describe` to lazy-load a version for this component
95 96 97 |
# File 'lib/vanagon/component/source/git.rb', line 95 def version @version end |
#workdir ⇒ Object
Returns the value of attribute workdir.
15 16 17 |
# File 'lib/vanagon/component/source/git.rb', line 15 def workdir @workdir end |
Class Method Details
.valid_remote?(url, timeout = 0) ⇒ Boolean
Attempt to connect to whatever URL is provided and return True or False depending on whether or not ‘git` thinks it’s a valid Git repo.
28 29 30 31 32 33 34 35 36 |
# File 'lib/vanagon/component/source/git.rb', line 28 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 Details
#cleanup ⇒ String
Return the correct incantation to cleanup the source directory for a given source
77 78 79 |
# File 'lib/vanagon/component/source/git.rb', line 77 def cleanup "rm -rf #{dirname}" end |
#clone ⇒ Object
Perform a git clone of @url as a lazy-loaded accessor for @clone
101 102 103 104 105 106 107 |
# File 'lib/vanagon/component/source/git.rb', line 101 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
90 91 92 |
# File 'lib/vanagon/component/source/git.rb', line 90 def 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.
67 68 69 70 71 72 |
# File 'lib/vanagon/component/source/git.rb', line 67 def fetch clone! checkout! version update_submodules end |
#verify ⇒ Object
There is no md5 to manually verify here, so this is a noop.
82 83 84 85 |
# File 'lib/vanagon/component/source/git.rb', line 82 def verify # nothing to do here, so just tell users that and return warn "Nothing to verify for '#{dirname}' (using Git reference '#{ref}')" end |