Sha256: 52d4242037d366be0432d3fc40dad9f9af5d539d788d99b9fe21a5215ac1a6e5
Contents?: true
Size: 988 Bytes
Versions: 4
Compression:
Stored size: 988 Bytes
Contents
# frozen_string_literal: true module Spandx module Core class Git attr_reader :root, :url def initialize(url:) @url = url @root = path_for(url) end def read(path) full_path = root.join(path) full_path.read if full_path.exist? end def update! dotgit? ? pull! : clone! end private def path_for(url) uri = URI.parse(url) name = uri.path.gsub(/\.git$/, '') Pathname(File.expand_path(File.join(Dir.home, '.local', 'share', name))) end def dotgit? root.join('.git').directory? end def clone! system('rm', '-rf', root.to_s) if root.exist? system('git', 'clone', '--quiet', '--depth=1', '--single-branch', '--branch', 'master', url, root.to_s) end def pull! Dir.chdir(root) do system('git', 'pull', '--no-rebase', '--quiet', 'origin', 'master') end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
spandx-0.15.1 | lib/spandx/core/git.rb |
spandx-0.15.0 | lib/spandx/core/git.rb |
spandx-0.14.0 | lib/spandx/core/git.rb |
spandx-0.13.5 | lib/spandx/core/git.rb |