From ca1dbbd5be2f254b6660bdc5c7f7f3f837d755aa Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Sat, 31 May 2025 13:53:57 +0200 Subject: [PATCH 1/3] Remove BasicSubmodules and related methods; use native config from git 3.x gem --- lib/git/basic_submodules.rb | 53 ----------------------------- lib/vanagon/component/source/git.rb | 13 ++----- spec/lib/vanagon/component_spec.rb | 2 -- vanagon.gemspec | 2 +- 4 files changed, 3 insertions(+), 67 deletions(-) delete mode 100644 lib/git/basic_submodules.rb diff --git a/lib/git/basic_submodules.rb b/lib/git/basic_submodules.rb deleted file mode 100644 index 37219c28..00000000 --- a/lib/git/basic_submodules.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'git' - -module BasicSubmodulePrimitives - # Extend Git::Lib to support shotgunning submodules. This command - # is not smart, and it has very poor support for submodule options. - # For example, you can't pass any arguments to the handful of submodule - # options that accept them (like --depth). We may extend it later, - # but for rev. 0001, simply initializing them will suffice - def update_submodules(**options) - arr_opts = ['update'] - options.each_pair do |k, v| - arr_opts << "--#{k}" if v - end - Dir.chdir(@git_work_dir) do - command('submodule', arr_opts) - end - end -end - -module BasicSubmodules - # @example Initialize all git submodules - # >> repo = Git.clone("git@github.com:puppetlabs/facter.git", "facter", path: Dir.mktmpdir) - # => - # >> repo.checkout "3.1.3 - # => - # >> repo.update_submodules(init: true) - # => - # @param [Hash] options any options to pass to `git submodule update` - # @option options [Boolean] :init whether to initialize submodules when updating them - # @option options [Boolean] :use the submodule's remote-tracking branch instead of superproject's SHA1 sum - # @option options [Boolean] :no-fetch don't fetch new objects from the remote site. - # @option options [Boolean] :force remove submodule's working tree even if modified - # @option options [Boolean] :checkout checkout submodules in detached HEAD state - # @option options [Boolean] :merge merge recorded commit for submodule into the current branch of the submodule - # @option options [Boolean] :rebase rebase current branch of submodule onto the commit recorded in the superproject - # @option options [Boolean] :recursive recurse into nested submodules - # @return options [String] any output produced by `git` when submodules are initialized - def update_submodules(**) - self.lib.update_submodules(**) - end -end - -module Git - class Lib - include BasicSubmodulePrimitives - end -end - -module Git - class Base - include BasicSubmodules - end -end diff --git a/lib/vanagon/component/source/git.rb b/lib/vanagon/component/source/git.rb index 743c8e31..a70a312a 100644 --- a/lib/vanagon/component/source/git.rb +++ b/lib/vanagon/component/source/git.rb @@ -5,7 +5,7 @@ # but it provides a wealth of useful constants require 'English' require 'build/uri' -require 'git/basic_submodules' +require 'git' require 'logger' require 'timeout' @@ -85,7 +85,7 @@ def github_source_type(url) # Default options used when cloning; this may expand # or change over time. def default_options # rubocop:disable Lint/DuplicateMethods - @default_options ||= { ref: "HEAD" } + @default_options ||= { ref: "HEAD", config: ['submodule.recurse=true'],} end private :default_options @@ -121,7 +121,6 @@ def fetch end checkout! version - update_submodules end # Return the correct incantation to cleanup the source directory for a given source @@ -201,14 +200,6 @@ def checkout! end private :checkout! - # Attempt to update submodules, and do not panic - # if there are no submodules to initialize - def update_submodules - VanagonLogger.info "Attempting to update submodules for repo '#{dirname}'" - clone.update_submodules(init: true) - end - private :update_submodules - # Determines a version for the given directory based on the git describe # for the repository # diff --git a/spec/lib/vanagon/component_spec.rb b/spec/lib/vanagon/component_spec.rb index 87ee485a..659a4cd7 100644 --- a/spec/lib/vanagon/component_spec.rb +++ b/spec/lib/vanagon/component_spec.rb @@ -285,7 +285,6 @@ allow(::Git).to receive(:clone).and_return(clone) allow(clone).to receive(:describe).and_return('4.5.6') allow(clone).to receive(:checkout).and_return(nil) - allow(clone).to receive(:update_submodules).and_return(nil) expect(component.force_version).to eq('4.5.6') end @@ -294,7 +293,6 @@ allow(::Git).to receive(:clone).and_return(clone) allow(clone).to receive(:describe).and_return(nil) allow(clone).to receive(:checkout).and_return(nil) - allow(clone).to receive(:update_submodules).and_return(nil) expect{ component.force_version }.to raise_error(Vanagon::Error, /unable to determine source version/i) end end diff --git a/vanagon.gemspec b/vanagon.gemspec index 1ade5ae6..ba3a8aab 100644 --- a/vanagon.gemspec +++ b/vanagon.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |gem| gem.add_dependency('docopt', '~> 0.6.1') # Handle git repos responsibly # - MIT licensed: https://rubygems.org/gems/git - gem.add_dependency('git', '>= 1.13', '< 4') + gem.add_dependency('git', '~> 3.1') # Parse scp-style triplets like URIs; used for Git source handling. # - MIT licensed: https://rubygems.org/gems/build-uri gem.add_dependency('build-uri', '~> 1.0') From 3b9698586bd8bea6b71dd15636c3638644cf3351 Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Sat, 31 May 2025 14:21:05 +0200 Subject: [PATCH 2/3] fix: remove space --- lib/vanagon/component/source/git.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vanagon/component/source/git.rb b/lib/vanagon/component/source/git.rb index a70a312a..bc28c03f 100644 --- a/lib/vanagon/component/source/git.rb +++ b/lib/vanagon/component/source/git.rb @@ -85,7 +85,7 @@ def github_source_type(url) # Default options used when cloning; this may expand # or change over time. def default_options # rubocop:disable Lint/DuplicateMethods - @default_options ||= { ref: "HEAD", config: ['submodule.recurse=true'],} + @default_options ||= { ref: "HEAD", config: ['submodule.recurse=true'],} end private :default_options From 1d162dbd229e330adfc47f2f5b4583d985da61fb Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Sat, 31 May 2025 14:26:33 +0200 Subject: [PATCH 3/3] fix: do rubocops biddings --- lib/vanagon/component/source/git.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vanagon/component/source/git.rb b/lib/vanagon/component/source/git.rb index bc28c03f..2af190e8 100644 --- a/lib/vanagon/component/source/git.rb +++ b/lib/vanagon/component/source/git.rb @@ -85,7 +85,7 @@ def github_source_type(url) # Default options used when cloning; this may expand # or change over time. def default_options # rubocop:disable Lint/DuplicateMethods - @default_options ||= { ref: "HEAD", config: ['submodule.recurse=true'],} + @default_options ||= { ref: "HEAD", config: ['submodule.recurse=true'] } end private :default_options