Module: PDK::Util::Git
- Defined in:
- lib/pdk/util/git.rb
Class Method Summary collapse
- .git(*args) ⇒ Object
- .git_bin ⇒ Object
- .git_bindir ⇒ Object
- .git_paths ⇒ Object
- .ls_remote(repo, ref) ⇒ Object
- .repo_exists?(repo, ref = nil) ⇒ Boolean
Class Method Details
.git(*args) ⇒ Object
29 30 31 32 33 |
# File 'lib/pdk/util/git.rb', line 29 def self.git(*args) PDK::CLI::Exec.ensure_bin_present!(git_bin, 'git') PDK::CLI::Exec.execute(git_bin, *args) end |
.git_bin ⇒ Object
22 23 24 25 26 27 |
# File 'lib/pdk/util/git.rb', line 22 def self.git_bin git_bin = Gem.win_platform? ? 'git.exe' : 'git' vendored_bin_path = File.join(git_bindir, git_bin) PDK::CLI::Exec.try_vendored_bin(vendored_bin_path, git_bin) end |
.git_bindir ⇒ Object
4 5 6 |
# File 'lib/pdk/util/git.rb', line 4 def self.git_bindir @git_dir ||= File.join('private', 'git', Gem.win_platform? ? 'cmd' : 'bin') end |
.git_paths ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/pdk/util/git.rb', line 8 def self.git_paths @paths ||= begin paths = [File.join(PDK::Util.pdk_package_basedir, git_bindir)] if Gem.win_platform? paths << File.join(PDK::Util.pdk_package_basedir, 'private', 'git', 'mingw64', 'bin') paths << File.join(PDK::Util.pdk_package_basedir, 'private', 'git', 'mingw64', 'libexec', 'git-core') paths << File.join(PDK::Util.pdk_package_basedir, 'private', 'git', 'usr', 'bin') end paths end end |
.ls_remote(repo, ref) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pdk/util/git.rb', line 41 def self.ls_remote(repo, ref) output = git('ls-remote', '--refs', repo, ref) unless output[:exit_code].zero? PDK.logger.error output[:stdout] PDK.logger.error output[:stderr] raise PDK::CLI::ExitWithError, _('Unable to access the template repository "%{repository}"') % { repository: repo, } end matching_refs = output[:stdout].split("\n").map { |r| r.split("\t") } matching_refs.find { |_sha, remote_ref| remote_ref == ref }.first end |
.repo_exists?(repo, ref = nil) ⇒ Boolean
35 36 37 38 39 |
# File 'lib/pdk/util/git.rb', line 35 def self.repo_exists?(repo, ref = nil) args = ['ls-remote', '--exit-code', repo, ref].compact git(*args)[:exit_code].zero? end |