diff options
| author | mo khan <mo.khan@gmail.com> | 2020-11-19 12:53:47 -0700 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-11-19 12:53:47 -0700 |
| commit | 13b7c67bfda4c92673deaca8cfe5ded960565e37 (patch) | |
| tree | 8c3d5c26dc6beb4df9d16166305ff96cc8df7b26 /lib | |
| parent | 4f08514da40651c601df65018b5534e458324f8a (diff) | |
feat: pull from main branch in cache repos
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/spandx.rb | 2 | ||||
| -rw-r--r-- | lib/spandx/cli/commands/pull.rb | 2 | ||||
| -rw-r--r-- | lib/spandx/core/git.rb | 16 |
3 files changed, 12 insertions, 8 deletions
diff --git a/lib/spandx.rb b/lib/spandx.rb index 78fbdcb..3567d75 100644 --- a/lib/spandx.rb +++ b/lib/spandx.rb @@ -45,7 +45,7 @@ module Spandx @git ||= { cache: ::Spandx::Core::Git.new(url: 'https://github.com/spandx/cache.git'), rubygems: ::Spandx::Core::Git.new(url: 'https://github.com/spandx/rubygems-cache.git'), - spdx: ::Spandx::Core::Git.new(url: 'https://github.com/spdx/license-list-data.git'), + spdx: ::Spandx::Core::Git.new(url: 'https://github.com/spdx/license-list-data.git', default_branch: 'master'), } end end diff --git a/lib/spandx/cli/commands/pull.rb b/lib/spandx/cli/commands/pull.rb index bcff1b0..c6d8107 100644 --- a/lib/spandx/cli/commands/pull.rb +++ b/lib/spandx/cli/commands/pull.rb @@ -41,6 +41,8 @@ module Spandx spinner.auto_spin yield spinner.success('(done)') + rescue StandardError => error + spinner.error("(#{error.message})") ensure spinner.stop end diff --git a/lib/spandx/core/git.rb b/lib/spandx/core/git.rb index 25716ab..170a721 100644 --- a/lib/spandx/core/git.rb +++ b/lib/spandx/core/git.rb @@ -3,10 +3,11 @@ module Spandx module Core class Git - attr_reader :root, :url + attr_reader :root, :url, :default_branch - def initialize(url:) + def initialize(url:, default_branch: 'main') @url = url + @default_branch = default_branch @root = path_for(url) end @@ -31,14 +32,15 @@ module Spandx 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) + def clone!(branch: default_branch) + system('rm', '-rf', root.to_s, exception: true) if root.exist? + system('git', 'clone', '--quiet', '--depth=1', '--single-branch', '--branch', branch, url, root.to_s, exception: true) end - def pull! + def pull!(remote: 'origin', branch: default_branch) Dir.chdir(root) do - system('git', 'pull', '--no-rebase', '--quiet', 'origin', 'master') + system('git', 'fetch', '--quiet', '--depth=1', '--prune', '--no-tags', remote, exception: true) + system('git', 'checkout', '--quiet', branch, exception: true) end end end |
