From 85ad3796bd0041e894c2d1ccd68810337745faa4 Mon Sep 17 00:00:00 2001 From: garryhurleyjr Date: Fri, 17 May 2024 22:50:58 -0400 Subject: [PATCH 01/20] Pushing changes in progress --- common/lib/dependabot/file_fetchers/base.rb | 28 +++++++++++---- .../dependabot/file_fetchers/base_spec.rb | 36 +++++++++++++++++++ 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/common/lib/dependabot/file_fetchers/base.rb b/common/lib/dependabot/file_fetchers/base.rb index d714a0400d..c0d55f0e95 100644 --- a/common/lib/dependabot/file_fetchers/base.rb +++ b/common/lib/dependabot/file_fetchers/base.rb @@ -861,19 +861,35 @@ def decode_binary_string(str) sig { params(path: String).returns(T::Array[String]) } def find_submodules(path) - SharedHelpers.run_shell_command( - <<~CMD - git -C #{path} ls-files --stage - CMD - ).split("\n").filter_map do |line| + lfsEnabled = true + commandString = getCommandString(path,lfsEnabled) + /debugger + p commandString/ + SharedHelpers.run_shell_command(commandString + ).split("\n").filter_map do |line| info = line.split type = info.first path = T.must(info.last) - +debugger next path if type == DependencyFile::Mode::SUBMODULE end end + + def getCommandString(path,lfsEnabled) + #the HEREDOC command will see any stray spaces. + return "git -C #{path} ls-files --stage" unless lfsEnabled + Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") + commandString = "CWD=\"#{__dir__}\";cd #{path};git-lfs ls-files --stage;cd $CWD" +# return "\"CWD=`pwd`;cd #{path};#git-lfs ls-files --stage;cd $CWD\"" + return commandString + end + + def getGitCommand(lfsEnabled) + return "git" unless !!lfsEnabled + Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") + return "git-lfs" + end end end end diff --git a/common/spec/dependabot/file_fetchers/base_spec.rb b/common/spec/dependabot/file_fetchers/base_spec.rb index 3b8720bd60..e37ffd3224 100644 --- a/common/spec/dependabot/file_fetchers/base_spec.rb +++ b/common/spec/dependabot/file_fetchers/base_spec.rb @@ -302,6 +302,42 @@ def fetch_files before do allow(file_fetcher_instance).to receive(:commit).and_return("sha") end + #start of lfs testing + context "with data stored in git-lfs" do +# debugger +# let(:source) do +# Dependabot::Source.new( +# provider: "github", +# repo: repo, +# directory: directory +# ) +# end + let(:url) { "https://api.github.com/repos/dependabot-fixtures/dependabot-yarn-lfs-fixture/contents/" } + let(:repo) { "dependabot-fixtures/dependabot-yarn-lfs-fixture" } + let(:repo_contents_path) { Dir.mktmpdir } + after { FileUtils.rm_rf(repo_contents_path) } + + let(:file_fetcher_instance) do + described_class.new(source: source, credentials: credentials, repo_contents_path: repo_contents_path) + end + + it "pulls files from lfs after cloning" do + # Calling #files triggers the clone + expect(file_fetcher_instance.files.map(&:name)).to contain_exactly("package.json", "yarn.lock", ".yarnrc.yml") + expect( + File.read( + File.join(repo_contents_path, ".yarn", "releases", "yarn-3.2.4.cjs") + ) + ).to start_with("#!/usr/bin/env node") + + # LFS files not needed by dependabot are not pulled + expect( + File.read( + File.join(repo_contents_path, ".pnp.cjs") + ) + ).to start_with("version https://git-lfs.github.com/spec/v1") + end + end context "with a GitHub source" do its(:length) { is_expected.to eq(1) } From b7858c54f51f628efc3752a75b01f8ed237cb231 Mon Sep 17 00:00:00 2001 From: garryhurleyjr Date: Thu, 23 May 2024 11:30:57 -0400 Subject: [PATCH 02/20] Corrected the approach for determining the command string. --- common/lib/dependabot/file_fetchers/base.rb | 60 +++++++++++++-------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/common/lib/dependabot/file_fetchers/base.rb b/common/lib/dependabot/file_fetchers/base.rb index c0d55f0e95..0bd9c48c10 100644 --- a/common/lib/dependabot/file_fetchers/base.rb +++ b/common/lib/dependabot/file_fetchers/base.rb @@ -157,6 +157,11 @@ def commit rescue Octokit::Conflict => e raise unless e.message.include?("Repository is empty") end + + /# Returns the path to the shallow-cloned repo + sig { overridable.returns(String) } + def shallow_clone_repo_contents + end/ # Returns the path to the cloned repo sig { overridable.returns(String) } @@ -441,12 +446,11 @@ def codecommit_client # INTERNAL METHODS (not for use by sub-classes) # ################################################# - sig do + sig { params(path: String, fetch_submodules: T::Boolean, raise_errors: T::Boolean) - .returns(T::Array[OpenStruct]) - end - def _fetch_repo_contents(path, fetch_submodules: false, - raise_errors: true) + .returns(T::Array[OpenStruct]) } + + def _fetch_repo_contents(path, fetch_submodules: false, raise_errors: true) path = path.gsub(" ", "%20") provider, repo, tmp_path, commit = _full_specification_for(path, fetch_submodules: fetch_submodules) @@ -476,10 +480,10 @@ def _fetch_repo_contents(path, fetch_submodules: false, retry end - sig do + sig { params(provider: String, repo: String, path: String, commit: String) - .returns(T::Array[OpenStruct]) - end + .returns(T::Array[OpenStruct]) } + def _fetch_repo_contents_fully_specified(provider, repo, path, commit) case provider when "github" @@ -861,36 +865,46 @@ def decode_binary_string(str) sig { params(path: String).returns(T::Array[String]) } def find_submodules(path) - lfsEnabled = true + lfsEnabled = isLfsEnabled(path) if lfsEnabled.nil? + commandString = getCommandString(path,lfsEnabled) - /debugger - p commandString/ - SharedHelpers.run_shell_command(commandString - ).split("\n").filter_map do |line| + + debugger + # eep commandString + SharedHelpers.run_shell_command(commandString).split("\n").filter_map do |line| info = line.split type = info.first path = T.must(info.last) -debugger +#debugger next path if type == DependencyFile::Mode::SUBMODULE end + #getFileList(path,lfsEnabled) + end + + sig { params(path: String).returns(T::Boolean) } + def isLfsEnabled(path) + filepath = File.join(path,".gitattributes") + lfsEnabled = FIle.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"") + rescue + # this should not be needed, but I don't trust 'should' + lfsEnabled = false end +# end + + sig { params(path: String, lfsEnabled: T::Boolean).returns(String) } def getCommandString(path,lfsEnabled) #the HEREDOC command will see any stray spaces. return "git -C #{path} ls-files --stage" unless lfsEnabled Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") - commandString = "CWD=\"#{__dir__}\";cd #{path};git-lfs ls-files --stage;cd $CWD" + commandString = "sh -c \"cd #{path};git-lfs ls-files --stage;\"" # return "\"CWD=`pwd`;cd #{path};#git-lfs ls-files --stage;cd $CWD\"" +#debugger return commandString end - def getGitCommand(lfsEnabled) - return "git" unless !!lfsEnabled - Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") - return "git-lfs" - end - end - end -end + end # end of class + end # end of module +end #end of module # rubocop:enable Metrics/ClassLength From 416f73c0f9212417371d5fd76b1c0a2d1987d699 Mon Sep 17 00:00:00 2001 From: garryhurleyjr Date: Fri, 24 May 2024 16:11:20 -0400 Subject: [PATCH 03/20] cleanup of common files --- common/lib/dependabot/file_fetchers/base.rb | 36 ++++++++++----------- common/lib/dependabot/shared_helpers.rb | 24 ++++++++++++-- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/common/lib/dependabot/file_fetchers/base.rb b/common/lib/dependabot/file_fetchers/base.rb index 0bd9c48c10..e6f3067fed 100644 --- a/common/lib/dependabot/file_fetchers/base.rb +++ b/common/lib/dependabot/file_fetchers/base.rb @@ -835,8 +835,13 @@ def _clone_repo_contents(target_directory:) " --recurse-submodules=on-demand" end # Need to fetch the commit due to the --depth 1 above. - SharedHelpers.run_shell_command("git fetch #{fetch_options.string} origin #{source.commit}") - + if isLfsEnabled(path) do + SharedHelpers.run_shell_command("git lfs install") + SharedHelpers.run_shell_command("git-lfs-fetch #{fetch_options.string} origin #{source.commit}") + end + else + SharedHelpers.run_shell_command("git fetch #{fetch_options.string} origin #{source.commit}") + end reset_options = StringIO.new reset_options << "--hard" reset_options << if submodule_cloning_failed @@ -866,20 +871,20 @@ def decode_binary_string(str) sig { params(path: String).returns(T::Array[String]) } def find_submodules(path) lfsEnabled = isLfsEnabled(path) if lfsEnabled.nil? - + SharedHelpers.run_shell_command("git-lfs-checkout") if lfsEnabled commandString = getCommandString(path,lfsEnabled) - - debugger - # eep commandString - SharedHelpers.run_shell_command(commandString).split("\n").filter_map do |line| + # eep commandString + SharedHelpers.run_shell_command(commandString)&.split("\n").filter_map do |line| info = line.split type = info.first path = T.must(info.last) -#debugger next path if type == DependencyFile::Mode::SUBMODULE end - #getFileList(path,lfsEnabled) + rescue SharedHelpers::HelperSubprocessFailed => spf + Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") if lfsEnabled + Dependabot.logger.error(spf.message) + raise end sig { params(path: String).returns(T::Boolean) } @@ -891,20 +896,15 @@ def isLfsEnabled(path) lfsEnabled = false end -# end - sig { params(path: String, lfsEnabled: T::Boolean).returns(String) } def getCommandString(path,lfsEnabled) - #the HEREDOC command will see any stray spaces. return "git -C #{path} ls-files --stage" unless lfsEnabled Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") - commandString = "sh -c \"cd #{path};git-lfs ls-files --stage;\"" -# return "\"CWD=`pwd`;cd #{path};#git-lfs ls-files --stage;cd $CWD\"" -#debugger + commandString = "cd #{path};git-lfs ls-files --stage" return commandString end - end # end of class - end # end of module -end #end of module + end + end +end # rubocop:enable Metrics/ClassLength diff --git a/common/lib/dependabot/shared_helpers.rb b/common/lib/dependabot/shared_helpers.rb index e57a3ccf5b..a86ccf9b73 100644 --- a/common/lib/dependabot/shared_helpers.rb +++ b/common/lib/dependabot/shared_helpers.rb @@ -374,12 +374,30 @@ def self.configure_git_to_use_https(host) sig { params(path: String).void } def self.reset_git_repo(path) - Dir.chdir(path) do - run_shell_command("git reset HEAD --hard") - run_shell_command("git clean -fx") + if isLfsEnabled(path) + Dir.chdir(path) do + run_shell_command("git-lfs-reset HEAD --hard") + rescue SharedHelpers::HelperSubprocessFailed + Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") + run_shell_command("git clean -fx") + end + else + Dir.chdir(path) do + run_shell_command("git reset HEAD --hard") + run_shell_command("git clean -fx") + end end end + sig { params(path: String).returns(T::Boolean) } + def self.isLfsEnabled(path) + filepath = File.join(path,".gitattributes") + lfsEnabled = FIle.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"") + rescue + # this should not be needed, but I don't trust 'should' + lfsEnabled = false + end + sig { returns(T::Array[String]) } def self.find_safe_directories # to preserve safe directories from global .gitconfig From 1be323c8046b70091b093fb76be4c24b5d6b0caa Mon Sep 17 00:00:00 2001 From: garryhurleyjr Date: Fri, 24 May 2024 16:17:57 -0400 Subject: [PATCH 04/20] cleanup of common files --- .../dependabot/file_fetchers/base_spec.rb | 38 +------------------ 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/common/spec/dependabot/file_fetchers/base_spec.rb b/common/spec/dependabot/file_fetchers/base_spec.rb index 9998e98d3c..93f5370045 100644 --- a/common/spec/dependabot/file_fetchers/base_spec.rb +++ b/common/spec/dependabot/file_fetchers/base_spec.rb @@ -303,42 +303,6 @@ def fetch_files allow(file_fetcher_instance).to receive(:commit).and_return("sha") end #start of lfs testing - context "with data stored in git-lfs" do -# debugger -# let(:source) do -# Dependabot::Source.new( -# provider: "github", -# repo: repo, -# directory: directory -# ) -# end - let(:url) { "https://api.github.com/repos/dependabot-fixtures/dependabot-yarn-lfs-fixture/contents/" } - let(:repo) { "dependabot-fixtures/dependabot-yarn-lfs-fixture" } - let(:repo_contents_path) { Dir.mktmpdir } - after { FileUtils.rm_rf(repo_contents_path) } - - let(:file_fetcher_instance) do - described_class.new(source: source, credentials: credentials, repo_contents_path: repo_contents_path) - end - - it "pulls files from lfs after cloning" do - # Calling #files triggers the clone - expect(file_fetcher_instance.files.map(&:name)).to contain_exactly("package.json", "yarn.lock", ".yarnrc.yml") - expect( - File.read( - File.join(repo_contents_path, ".yarn", "releases", "yarn-3.2.4.cjs") - ) - ).to start_with("#!/usr/bin/env node") - - # LFS files not needed by dependabot are not pulled - expect( - File.read( - File.join(repo_contents_path, ".pnp.cjs") - ) - ).to start_with("version https://git-lfs.github.com/spec/v1") - end - end - context "with a GitHub source" do its(:length) { is_expected.to eq(1) } @@ -1669,7 +1633,7 @@ def fetch_files end end - context "when a retryable error occurs" do + context "when a retryable error occurs", focus: true do let(:retryable_error) do proc { raise Dependabot::SharedHelpers::HelperSubprocessFailed.new( From fed7b2137f56ffd2ead1274fc73bd59afd667fa7 Mon Sep 17 00:00:00 2001 From: garryhurleyjr Date: Wed, 29 May 2024 11:42:47 -0400 Subject: [PATCH 05/20] Git class updates --- common/lib/dependabot/workspace/git.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/common/lib/dependabot/workspace/git.rb b/common/lib/dependabot/workspace/git.rb index bd9411bf83..6b55f32a7b 100644 --- a/common/lib/dependabot/workspace/git.rb +++ b/common/lib/dependabot/workspace/git.rb @@ -13,6 +13,7 @@ class Git < Base USER = "dependabot[bot]" EMAIL = T.let("#{USER}@users.noreply.github.com".freeze, String) + lfsEnabled = nil sig { returns(String) } attr_reader :initial_head_sha @@ -22,6 +23,7 @@ def initialize(path) super(path) @initial_head_sha = T.let(head_sha, String) configure_git + run_shell_command("git lfs install") if isLfsEnabled(path.to_s) end sig { returns(T::Boolean) } @@ -168,6 +170,16 @@ def run_shell_command(*args, **kwargs) def debug(message) Dependabot.logger.debug("[workspace] #{message}") end + + sig { params(path: String).returns(T::Boolean) } + def isLfsEnabled(path) + filepath = File.join(path,".gitattributes") + lfsEnabled = FIle.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"") if lfsEnabled.nil? + rescue + # this should not be needed, but I don't trust 'should' + lfsEnabled = false + end + end end end From 859e451ebbf92dd9c78cc8b0e88749ff9bf6cf34 Mon Sep 17 00:00:00 2001 From: garryhurleyjr Date: Fri, 17 May 2024 22:50:58 -0400 Subject: [PATCH 06/20] Pushing changes in progress --- common/lib/dependabot/file_fetchers/base.rb | 28 +++++++++++---- .../dependabot/file_fetchers/base_spec.rb | 36 +++++++++++++++++++ 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/common/lib/dependabot/file_fetchers/base.rb b/common/lib/dependabot/file_fetchers/base.rb index d714a0400d..c0d55f0e95 100644 --- a/common/lib/dependabot/file_fetchers/base.rb +++ b/common/lib/dependabot/file_fetchers/base.rb @@ -861,19 +861,35 @@ def decode_binary_string(str) sig { params(path: String).returns(T::Array[String]) } def find_submodules(path) - SharedHelpers.run_shell_command( - <<~CMD - git -C #{path} ls-files --stage - CMD - ).split("\n").filter_map do |line| + lfsEnabled = true + commandString = getCommandString(path,lfsEnabled) + /debugger + p commandString/ + SharedHelpers.run_shell_command(commandString + ).split("\n").filter_map do |line| info = line.split type = info.first path = T.must(info.last) - +debugger next path if type == DependencyFile::Mode::SUBMODULE end end + + def getCommandString(path,lfsEnabled) + #the HEREDOC command will see any stray spaces. + return "git -C #{path} ls-files --stage" unless lfsEnabled + Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") + commandString = "CWD=\"#{__dir__}\";cd #{path};git-lfs ls-files --stage;cd $CWD" +# return "\"CWD=`pwd`;cd #{path};#git-lfs ls-files --stage;cd $CWD\"" + return commandString + end + + def getGitCommand(lfsEnabled) + return "git" unless !!lfsEnabled + Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") + return "git-lfs" + end end end end diff --git a/common/spec/dependabot/file_fetchers/base_spec.rb b/common/spec/dependabot/file_fetchers/base_spec.rb index b7f4d30bdb..ae4ce8894a 100644 --- a/common/spec/dependabot/file_fetchers/base_spec.rb +++ b/common/spec/dependabot/file_fetchers/base_spec.rb @@ -304,6 +304,42 @@ def fetch_files before do allow(file_fetcher_instance).to receive(:commit).and_return("sha") end + #start of lfs testing + context "with data stored in git-lfs" do +# debugger +# let(:source) do +# Dependabot::Source.new( +# provider: "github", +# repo: repo, +# directory: directory +# ) +# end + let(:url) { "https://api.github.com/repos/dependabot-fixtures/dependabot-yarn-lfs-fixture/contents/" } + let(:repo) { "dependabot-fixtures/dependabot-yarn-lfs-fixture" } + let(:repo_contents_path) { Dir.mktmpdir } + after { FileUtils.rm_rf(repo_contents_path) } + + let(:file_fetcher_instance) do + described_class.new(source: source, credentials: credentials, repo_contents_path: repo_contents_path) + end + + it "pulls files from lfs after cloning" do + # Calling #files triggers the clone + expect(file_fetcher_instance.files.map(&:name)).to contain_exactly("package.json", "yarn.lock", ".yarnrc.yml") + expect( + File.read( + File.join(repo_contents_path, ".yarn", "releases", "yarn-3.2.4.cjs") + ) + ).to start_with("#!/usr/bin/env node") + + # LFS files not needed by dependabot are not pulled + expect( + File.read( + File.join(repo_contents_path, ".pnp.cjs") + ) + ).to start_with("version https://git-lfs.github.com/spec/v1") + end + end context "with a GitHub source" do its(:length) { is_expected.to eq(1) } From b58fb65db65fac1266bf6a32cbca641b0ae8fe48 Mon Sep 17 00:00:00 2001 From: garryhurleyjr Date: Thu, 23 May 2024 11:30:57 -0400 Subject: [PATCH 07/20] Corrected the approach for determining the command string. --- common/lib/dependabot/file_fetchers/base.rb | 60 +++++++++++++-------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/common/lib/dependabot/file_fetchers/base.rb b/common/lib/dependabot/file_fetchers/base.rb index c0d55f0e95..0bd9c48c10 100644 --- a/common/lib/dependabot/file_fetchers/base.rb +++ b/common/lib/dependabot/file_fetchers/base.rb @@ -157,6 +157,11 @@ def commit rescue Octokit::Conflict => e raise unless e.message.include?("Repository is empty") end + + /# Returns the path to the shallow-cloned repo + sig { overridable.returns(String) } + def shallow_clone_repo_contents + end/ # Returns the path to the cloned repo sig { overridable.returns(String) } @@ -441,12 +446,11 @@ def codecommit_client # INTERNAL METHODS (not for use by sub-classes) # ################################################# - sig do + sig { params(path: String, fetch_submodules: T::Boolean, raise_errors: T::Boolean) - .returns(T::Array[OpenStruct]) - end - def _fetch_repo_contents(path, fetch_submodules: false, - raise_errors: true) + .returns(T::Array[OpenStruct]) } + + def _fetch_repo_contents(path, fetch_submodules: false, raise_errors: true) path = path.gsub(" ", "%20") provider, repo, tmp_path, commit = _full_specification_for(path, fetch_submodules: fetch_submodules) @@ -476,10 +480,10 @@ def _fetch_repo_contents(path, fetch_submodules: false, retry end - sig do + sig { params(provider: String, repo: String, path: String, commit: String) - .returns(T::Array[OpenStruct]) - end + .returns(T::Array[OpenStruct]) } + def _fetch_repo_contents_fully_specified(provider, repo, path, commit) case provider when "github" @@ -861,36 +865,46 @@ def decode_binary_string(str) sig { params(path: String).returns(T::Array[String]) } def find_submodules(path) - lfsEnabled = true + lfsEnabled = isLfsEnabled(path) if lfsEnabled.nil? + commandString = getCommandString(path,lfsEnabled) - /debugger - p commandString/ - SharedHelpers.run_shell_command(commandString - ).split("\n").filter_map do |line| + + debugger + # eep commandString + SharedHelpers.run_shell_command(commandString).split("\n").filter_map do |line| info = line.split type = info.first path = T.must(info.last) -debugger +#debugger next path if type == DependencyFile::Mode::SUBMODULE end + #getFileList(path,lfsEnabled) + end + + sig { params(path: String).returns(T::Boolean) } + def isLfsEnabled(path) + filepath = File.join(path,".gitattributes") + lfsEnabled = FIle.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"") + rescue + # this should not be needed, but I don't trust 'should' + lfsEnabled = false end +# end + + sig { params(path: String, lfsEnabled: T::Boolean).returns(String) } def getCommandString(path,lfsEnabled) #the HEREDOC command will see any stray spaces. return "git -C #{path} ls-files --stage" unless lfsEnabled Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") - commandString = "CWD=\"#{__dir__}\";cd #{path};git-lfs ls-files --stage;cd $CWD" + commandString = "sh -c \"cd #{path};git-lfs ls-files --stage;\"" # return "\"CWD=`pwd`;cd #{path};#git-lfs ls-files --stage;cd $CWD\"" +#debugger return commandString end - def getGitCommand(lfsEnabled) - return "git" unless !!lfsEnabled - Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") - return "git-lfs" - end - end - end -end + end # end of class + end # end of module +end #end of module # rubocop:enable Metrics/ClassLength From 00b1f37dc4700dd4bf167d30712b3ba429fb0de8 Mon Sep 17 00:00:00 2001 From: garryhurleyjr Date: Fri, 24 May 2024 16:11:20 -0400 Subject: [PATCH 08/20] cleanup of common files --- common/lib/dependabot/file_fetchers/base.rb | 36 ++++++++++----------- common/lib/dependabot/shared_helpers.rb | 24 ++++++++++++-- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/common/lib/dependabot/file_fetchers/base.rb b/common/lib/dependabot/file_fetchers/base.rb index 0bd9c48c10..e6f3067fed 100644 --- a/common/lib/dependabot/file_fetchers/base.rb +++ b/common/lib/dependabot/file_fetchers/base.rb @@ -835,8 +835,13 @@ def _clone_repo_contents(target_directory:) " --recurse-submodules=on-demand" end # Need to fetch the commit due to the --depth 1 above. - SharedHelpers.run_shell_command("git fetch #{fetch_options.string} origin #{source.commit}") - + if isLfsEnabled(path) do + SharedHelpers.run_shell_command("git lfs install") + SharedHelpers.run_shell_command("git-lfs-fetch #{fetch_options.string} origin #{source.commit}") + end + else + SharedHelpers.run_shell_command("git fetch #{fetch_options.string} origin #{source.commit}") + end reset_options = StringIO.new reset_options << "--hard" reset_options << if submodule_cloning_failed @@ -866,20 +871,20 @@ def decode_binary_string(str) sig { params(path: String).returns(T::Array[String]) } def find_submodules(path) lfsEnabled = isLfsEnabled(path) if lfsEnabled.nil? - + SharedHelpers.run_shell_command("git-lfs-checkout") if lfsEnabled commandString = getCommandString(path,lfsEnabled) - - debugger - # eep commandString - SharedHelpers.run_shell_command(commandString).split("\n").filter_map do |line| + # eep commandString + SharedHelpers.run_shell_command(commandString)&.split("\n").filter_map do |line| info = line.split type = info.first path = T.must(info.last) -#debugger next path if type == DependencyFile::Mode::SUBMODULE end - #getFileList(path,lfsEnabled) + rescue SharedHelpers::HelperSubprocessFailed => spf + Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") if lfsEnabled + Dependabot.logger.error(spf.message) + raise end sig { params(path: String).returns(T::Boolean) } @@ -891,20 +896,15 @@ def isLfsEnabled(path) lfsEnabled = false end -# end - sig { params(path: String, lfsEnabled: T::Boolean).returns(String) } def getCommandString(path,lfsEnabled) - #the HEREDOC command will see any stray spaces. return "git -C #{path} ls-files --stage" unless lfsEnabled Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") - commandString = "sh -c \"cd #{path};git-lfs ls-files --stage;\"" -# return "\"CWD=`pwd`;cd #{path};#git-lfs ls-files --stage;cd $CWD\"" -#debugger + commandString = "cd #{path};git-lfs ls-files --stage" return commandString end - end # end of class - end # end of module -end #end of module + end + end +end # rubocop:enable Metrics/ClassLength diff --git a/common/lib/dependabot/shared_helpers.rb b/common/lib/dependabot/shared_helpers.rb index e57a3ccf5b..a86ccf9b73 100644 --- a/common/lib/dependabot/shared_helpers.rb +++ b/common/lib/dependabot/shared_helpers.rb @@ -374,12 +374,30 @@ def self.configure_git_to_use_https(host) sig { params(path: String).void } def self.reset_git_repo(path) - Dir.chdir(path) do - run_shell_command("git reset HEAD --hard") - run_shell_command("git clean -fx") + if isLfsEnabled(path) + Dir.chdir(path) do + run_shell_command("git-lfs-reset HEAD --hard") + rescue SharedHelpers::HelperSubprocessFailed + Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") + run_shell_command("git clean -fx") + end + else + Dir.chdir(path) do + run_shell_command("git reset HEAD --hard") + run_shell_command("git clean -fx") + end end end + sig { params(path: String).returns(T::Boolean) } + def self.isLfsEnabled(path) + filepath = File.join(path,".gitattributes") + lfsEnabled = FIle.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"") + rescue + # this should not be needed, but I don't trust 'should' + lfsEnabled = false + end + sig { returns(T::Array[String]) } def self.find_safe_directories # to preserve safe directories from global .gitconfig From aa9e64ea0a29fc5e368a3702c26d9801cbf37902 Mon Sep 17 00:00:00 2001 From: garryhurleyjr Date: Fri, 24 May 2024 16:17:57 -0400 Subject: [PATCH 09/20] cleanup of common files --- .../dependabot/file_fetchers/base_spec.rb | 38 +------------------ 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/common/spec/dependabot/file_fetchers/base_spec.rb b/common/spec/dependabot/file_fetchers/base_spec.rb index ae4ce8894a..aac1dcc03d 100644 --- a/common/spec/dependabot/file_fetchers/base_spec.rb +++ b/common/spec/dependabot/file_fetchers/base_spec.rb @@ -305,42 +305,6 @@ def fetch_files allow(file_fetcher_instance).to receive(:commit).and_return("sha") end #start of lfs testing - context "with data stored in git-lfs" do -# debugger -# let(:source) do -# Dependabot::Source.new( -# provider: "github", -# repo: repo, -# directory: directory -# ) -# end - let(:url) { "https://api.github.com/repos/dependabot-fixtures/dependabot-yarn-lfs-fixture/contents/" } - let(:repo) { "dependabot-fixtures/dependabot-yarn-lfs-fixture" } - let(:repo_contents_path) { Dir.mktmpdir } - after { FileUtils.rm_rf(repo_contents_path) } - - let(:file_fetcher_instance) do - described_class.new(source: source, credentials: credentials, repo_contents_path: repo_contents_path) - end - - it "pulls files from lfs after cloning" do - # Calling #files triggers the clone - expect(file_fetcher_instance.files.map(&:name)).to contain_exactly("package.json", "yarn.lock", ".yarnrc.yml") - expect( - File.read( - File.join(repo_contents_path, ".yarn", "releases", "yarn-3.2.4.cjs") - ) - ).to start_with("#!/usr/bin/env node") - - # LFS files not needed by dependabot are not pulled - expect( - File.read( - File.join(repo_contents_path, ".pnp.cjs") - ) - ).to start_with("version https://git-lfs.github.com/spec/v1") - end - end - context "with a GitHub source" do its(:length) { is_expected.to eq(1) } @@ -1679,7 +1643,7 @@ def fetch_files end end - context "when a retryable error occurs" do + context "when a retryable error occurs", focus: true do let(:retryable_error) do proc { raise Dependabot::SharedHelpers::HelperSubprocessFailed.new( From e610181f663f0f2a889abe6de38318168a92a323 Mon Sep 17 00:00:00 2001 From: garryhurleyjr Date: Wed, 29 May 2024 11:42:47 -0400 Subject: [PATCH 10/20] Git class updates --- common/lib/dependabot/workspace/git.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/common/lib/dependabot/workspace/git.rb b/common/lib/dependabot/workspace/git.rb index bd9411bf83..6b55f32a7b 100644 --- a/common/lib/dependabot/workspace/git.rb +++ b/common/lib/dependabot/workspace/git.rb @@ -13,6 +13,7 @@ class Git < Base USER = "dependabot[bot]" EMAIL = T.let("#{USER}@users.noreply.github.com".freeze, String) + lfsEnabled = nil sig { returns(String) } attr_reader :initial_head_sha @@ -22,6 +23,7 @@ def initialize(path) super(path) @initial_head_sha = T.let(head_sha, String) configure_git + run_shell_command("git lfs install") if isLfsEnabled(path.to_s) end sig { returns(T::Boolean) } @@ -168,6 +170,16 @@ def run_shell_command(*args, **kwargs) def debug(message) Dependabot.logger.debug("[workspace] #{message}") end + + sig { params(path: String).returns(T::Boolean) } + def isLfsEnabled(path) + filepath = File.join(path,".gitattributes") + lfsEnabled = FIle.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"") if lfsEnabled.nil? + rescue + # this should not be needed, but I don't trust 'should' + lfsEnabled = false + end + end end end From 512226c61cfbc5f0d2d76e37d1d529405536f704 Mon Sep 17 00:00:00 2001 From: garryhurleyjr Date: Wed, 29 May 2024 15:52:58 -0400 Subject: [PATCH 11/20] sorbet fixes --- common/lib/dependabot/file_fetchers/base.rb | 6 +++--- common/lib/dependabot/shared_helpers.rb | 3 ++- common/lib/dependabot/workspace/git.rb | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/common/lib/dependabot/file_fetchers/base.rb b/common/lib/dependabot/file_fetchers/base.rb index e6f3067fed..45c459ecd4 100644 --- a/common/lib/dependabot/file_fetchers/base.rb +++ b/common/lib/dependabot/file_fetchers/base.rb @@ -835,7 +835,7 @@ def _clone_repo_contents(target_directory:) " --recurse-submodules=on-demand" end # Need to fetch the commit due to the --depth 1 above. - if isLfsEnabled(path) do + if isLfsEnabled(path.to_s) do SharedHelpers.run_shell_command("git lfs install") SharedHelpers.run_shell_command("git-lfs-fetch #{fetch_options.string} origin #{source.commit}") end @@ -874,7 +874,7 @@ def find_submodules(path) SharedHelpers.run_shell_command("git-lfs-checkout") if lfsEnabled commandString = getCommandString(path,lfsEnabled) # eep commandString - SharedHelpers.run_shell_command(commandString)&.split("\n").filter_map do |line| + SharedHelpers.run_shell_command(commandString).split("\n").filter_map do |line| info = line.split type = info.first @@ -890,7 +890,7 @@ def find_submodules(path) sig { params(path: String).returns(T::Boolean) } def isLfsEnabled(path) filepath = File.join(path,".gitattributes") - lfsEnabled = FIle.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"") + lfsEnabled = File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include? "#{filepath}" rescue # this should not be needed, but I don't trust 'should' lfsEnabled = false diff --git a/common/lib/dependabot/shared_helpers.rb b/common/lib/dependabot/shared_helpers.rb index a86ccf9b73..f1c96495ed 100644 --- a/common/lib/dependabot/shared_helpers.rb +++ b/common/lib/dependabot/shared_helpers.rb @@ -392,12 +392,13 @@ def self.reset_git_repo(path) sig { params(path: String).returns(T::Boolean) } def self.isLfsEnabled(path) filepath = File.join(path,".gitattributes") - lfsEnabled = FIle.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"") + lfsEnabled = File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include? "#{filepath}" rescue # this should not be needed, but I don't trust 'should' lfsEnabled = false end + sig { returns(T::Array[String]) } def self.find_safe_directories # to preserve safe directories from global .gitconfig diff --git a/common/lib/dependabot/workspace/git.rb b/common/lib/dependabot/workspace/git.rb index 6b55f32a7b..7e434a3e22 100644 --- a/common/lib/dependabot/workspace/git.rb +++ b/common/lib/dependabot/workspace/git.rb @@ -174,7 +174,7 @@ def debug(message) sig { params(path: String).returns(T::Boolean) } def isLfsEnabled(path) filepath = File.join(path,".gitattributes") - lfsEnabled = FIle.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"") if lfsEnabled.nil? + lfsEnabled = File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include? "#{filepath}" rescue # this should not be needed, but I don't trust 'should' lfsEnabled = false From 38808442288eec6d931e5a74dd4cac55f6d0905b Mon Sep 17 00:00:00 2001 From: garryhurleyjr Date: Wed, 29 May 2024 16:15:48 -0400 Subject: [PATCH 12/20] sorbet fixes --- common/lib/dependabot/file_fetchers/base.rb | 4 ++-- common/lib/dependabot/shared_helpers.rb | 4 ++-- common/lib/dependabot/workspace/git.rb | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/common/lib/dependabot/file_fetchers/base.rb b/common/lib/dependabot/file_fetchers/base.rb index 45c459ecd4..b1cf54d5d1 100644 --- a/common/lib/dependabot/file_fetchers/base.rb +++ b/common/lib/dependabot/file_fetchers/base.rb @@ -890,10 +890,10 @@ def find_submodules(path) sig { params(path: String).returns(T::Boolean) } def isLfsEnabled(path) filepath = File.join(path,".gitattributes") - lfsEnabled = File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include? "#{filepath}" + lfsEnabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include? "filter=lfs" rescue # this should not be needed, but I don't trust 'should' - lfsEnabled = false + lfsEnabled = T.let(false, T::Boolean) end sig { params(path: String, lfsEnabled: T::Boolean).returns(String) } diff --git a/common/lib/dependabot/shared_helpers.rb b/common/lib/dependabot/shared_helpers.rb index f1c96495ed..10298191ca 100644 --- a/common/lib/dependabot/shared_helpers.rb +++ b/common/lib/dependabot/shared_helpers.rb @@ -392,10 +392,10 @@ def self.reset_git_repo(path) sig { params(path: String).returns(T::Boolean) } def self.isLfsEnabled(path) filepath = File.join(path,".gitattributes") - lfsEnabled = File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include? "#{filepath}" + lfsEnabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include? "filter=lfs" rescue # this should not be needed, but I don't trust 'should' - lfsEnabled = false + lfsEnabled = T.let(false, T::Boolean) end diff --git a/common/lib/dependabot/workspace/git.rb b/common/lib/dependabot/workspace/git.rb index 7e434a3e22..5a6d927b62 100644 --- a/common/lib/dependabot/workspace/git.rb +++ b/common/lib/dependabot/workspace/git.rb @@ -174,10 +174,10 @@ def debug(message) sig { params(path: String).returns(T::Boolean) } def isLfsEnabled(path) filepath = File.join(path,".gitattributes") - lfsEnabled = File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include? "#{filepath}" + lfsEnabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include? "filter=lfs" rescue # this should not be needed, but I don't trust 'should' - lfsEnabled = false + lfsEnabled = T.let(false, T::Boolean) end end From 727843217b6b5e080e3f92a9784c180d73164a5f Mon Sep 17 00:00:00 2001 From: garryhurleyjr Date: Wed, 29 May 2024 16:32:53 -0400 Subject: [PATCH 13/20] sorbet fixes --- common/lib/dependabot/file_fetchers/base.rb | 4 ++-- common/lib/dependabot/shared_helpers.rb | 2 +- common/lib/dependabot/workspace/git.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/lib/dependabot/file_fetchers/base.rb b/common/lib/dependabot/file_fetchers/base.rb index b1cf54d5d1..e6f5e8db7e 100644 --- a/common/lib/dependabot/file_fetchers/base.rb +++ b/common/lib/dependabot/file_fetchers/base.rb @@ -887,7 +887,7 @@ def find_submodules(path) raise end - sig { params(path: String).returns(T::Boolean) } + sig { params(path: String).returns(T.nilable(T::Boolean)) } def isLfsEnabled(path) filepath = File.join(path,".gitattributes") lfsEnabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include? "filter=lfs" @@ -896,7 +896,7 @@ def isLfsEnabled(path) lfsEnabled = T.let(false, T::Boolean) end - sig { params(path: String, lfsEnabled: T::Boolean).returns(String) } + sig { params(path: String, lfsEnabled: T.nilable(T::Boolean)).returns(String) } def getCommandString(path,lfsEnabled) return "git -C #{path} ls-files --stage" unless lfsEnabled Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") diff --git a/common/lib/dependabot/shared_helpers.rb b/common/lib/dependabot/shared_helpers.rb index 10298191ca..2d64429b6e 100644 --- a/common/lib/dependabot/shared_helpers.rb +++ b/common/lib/dependabot/shared_helpers.rb @@ -389,7 +389,7 @@ def self.reset_git_repo(path) end end - sig { params(path: String).returns(T::Boolean) } + sig { params(path: String).returns(T.nilable(T::Boolean)) } def self.isLfsEnabled(path) filepath = File.join(path,".gitattributes") lfsEnabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include? "filter=lfs" diff --git a/common/lib/dependabot/workspace/git.rb b/common/lib/dependabot/workspace/git.rb index 5a6d927b62..c95699936d 100644 --- a/common/lib/dependabot/workspace/git.rb +++ b/common/lib/dependabot/workspace/git.rb @@ -171,7 +171,7 @@ def debug(message) Dependabot.logger.debug("[workspace] #{message}") end - sig { params(path: String).returns(T::Boolean) } + sig { params(path: String).returns(T.nilable(T::Boolean)) } def isLfsEnabled(path) filepath = File.join(path,".gitattributes") lfsEnabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include? "filter=lfs" From 6ac6646baf05f0131c9de6253bd2034e7ed3f248 Mon Sep 17 00:00:00 2001 From: garryhurleyjr Date: Wed, 29 May 2024 18:04:10 -0400 Subject: [PATCH 14/20] sorbet fixes --- common/lib/dependabot/file_fetchers/base.rb | 9 ++++----- common/lib/dependabot/shared_helpers.rb | 2 +- common/lib/dependabot/workspace/git.rb | 2 +- common/spec/dependabot/file_fetchers/base_spec.rb | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/common/lib/dependabot/file_fetchers/base.rb b/common/lib/dependabot/file_fetchers/base.rb index e6f5e8db7e..5bfb99ea63 100644 --- a/common/lib/dependabot/file_fetchers/base.rb +++ b/common/lib/dependabot/file_fetchers/base.rb @@ -835,10 +835,9 @@ def _clone_repo_contents(target_directory:) " --recurse-submodules=on-demand" end # Need to fetch the commit due to the --depth 1 above. - if isLfsEnabled(path.to_s) do - SharedHelpers.run_shell_command("git lfs install") - SharedHelpers.run_shell_command("git-lfs-fetch #{fetch_options.string} origin #{source.commit}") - end + if isLfsEnabled(path.to_s) + SharedHelpers.run_shell_command("git lfs install") + SharedHelpers.run_shell_command("git-lfs-fetch #{fetch_options.string} origin #{source.commit}") else SharedHelpers.run_shell_command("git fetch #{fetch_options.string} origin #{source.commit}") end @@ -890,7 +889,7 @@ def find_submodules(path) sig { params(path: String).returns(T.nilable(T::Boolean)) } def isLfsEnabled(path) filepath = File.join(path,".gitattributes") - lfsEnabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include? "filter=lfs" + lfsEnabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include?("filter=lfs") rescue # this should not be needed, but I don't trust 'should' lfsEnabled = T.let(false, T::Boolean) diff --git a/common/lib/dependabot/shared_helpers.rb b/common/lib/dependabot/shared_helpers.rb index 2d64429b6e..8e8acd2b07 100644 --- a/common/lib/dependabot/shared_helpers.rb +++ b/common/lib/dependabot/shared_helpers.rb @@ -392,7 +392,7 @@ def self.reset_git_repo(path) sig { params(path: String).returns(T.nilable(T::Boolean)) } def self.isLfsEnabled(path) filepath = File.join(path,".gitattributes") - lfsEnabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include? "filter=lfs" + lfsEnabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include?("filter=lfs") rescue # this should not be needed, but I don't trust 'should' lfsEnabled = T.let(false, T::Boolean) diff --git a/common/lib/dependabot/workspace/git.rb b/common/lib/dependabot/workspace/git.rb index c95699936d..1d3dc278df 100644 --- a/common/lib/dependabot/workspace/git.rb +++ b/common/lib/dependabot/workspace/git.rb @@ -174,7 +174,7 @@ def debug(message) sig { params(path: String).returns(T.nilable(T::Boolean)) } def isLfsEnabled(path) filepath = File.join(path,".gitattributes") - lfsEnabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include? "filter=lfs" + lfsEnabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include?("filter=lfs") rescue # this should not be needed, but I don't trust 'should' lfsEnabled = T.let(false, T::Boolean) diff --git a/common/spec/dependabot/file_fetchers/base_spec.rb b/common/spec/dependabot/file_fetchers/base_spec.rb index aac1dcc03d..be3364b3f7 100644 --- a/common/spec/dependabot/file_fetchers/base_spec.rb +++ b/common/spec/dependabot/file_fetchers/base_spec.rb @@ -304,7 +304,7 @@ def fetch_files before do allow(file_fetcher_instance).to receive(:commit).and_return("sha") end - #start of lfs testing + context "with a GitHub source" do its(:length) { is_expected.to eq(1) } From 32cf3339c0099d7f72cbaa64959473885d903f95 Mon Sep 17 00:00:00 2001 From: garryhurleyjr Date: Wed, 29 May 2024 18:49:24 -0400 Subject: [PATCH 15/20] lint fixes --- common/lib/dependabot/file_fetchers/base.rb | 47 ++++++++------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/common/lib/dependabot/file_fetchers/base.rb b/common/lib/dependabot/file_fetchers/base.rb index 5bfb99ea63..479ff5cdf1 100644 --- a/common/lib/dependabot/file_fetchers/base.rb +++ b/common/lib/dependabot/file_fetchers/base.rb @@ -157,11 +157,6 @@ def commit rescue Octokit::Conflict => e raise unless e.message.include?("Repository is empty") end - - /# Returns the path to the shallow-cloned repo - sig { overridable.returns(String) } - def shallow_clone_repo_contents - end/ # Returns the path to the cloned repo sig { overridable.returns(String) } @@ -446,10 +441,7 @@ def codecommit_client # INTERNAL METHODS (not for use by sub-classes) # ################################################# - sig { - params(path: String, fetch_submodules: T::Boolean, raise_errors: T::Boolean) - .returns(T::Array[OpenStruct]) } - + sig { params(path: String, fetch_submodules: T::Boolean, raise_errors: T::Boolean).returns(T::Array[OpenStruct]) } def _fetch_repo_contents(path, fetch_submodules: false, raise_errors: true) path = path.gsub(" ", "%20") provider, repo, tmp_path, commit = @@ -480,10 +472,7 @@ def _fetch_repo_contents(path, fetch_submodules: false, raise_errors: true) retry end - sig { - params(provider: String, repo: String, path: String, commit: String) - .returns(T::Array[OpenStruct]) } - + sig { params(provider: String, repo: String, path: String, commit: String).returns(T::Array[OpenStruct]) } def _fetch_repo_contents_fully_specified(provider, repo, path, commit) case provider when "github" @@ -835,10 +824,10 @@ def _clone_repo_contents(target_directory:) " --recurse-submodules=on-demand" end # Need to fetch the commit due to the --depth 1 above. - if isLfsEnabled(path.to_s) - SharedHelpers.run_shell_command("git lfs install") + if isLfsEnabled(path.to_s) + SharedHelpers.run_shell_command("git lfs install") SharedHelpers.run_shell_command("git-lfs-fetch #{fetch_options.string} origin #{source.commit}") - else + else SharedHelpers.run_shell_command("git fetch #{fetch_options.string} origin #{source.commit}") end reset_options = StringIO.new @@ -869,11 +858,11 @@ def decode_binary_string(str) sig { params(path: String).returns(T::Array[String]) } def find_submodules(path) - lfsEnabled = isLfsEnabled(path) if lfsEnabled.nil? - SharedHelpers.run_shell_command("git-lfs-checkout") if lfsEnabled - commandString = getCommandString(path,lfsEnabled) - # eep commandString - SharedHelpers.run_shell_command(commandString).split("\n").filter_map do |line| + lfs_enabled = isLfsEnabled(path) if lfs_enabled.nil? + SharedHelpers.run_shell_command("git-lfs-checkout") if lfs_enabled + command_string = getCommandString(path,lfs_enabled) + # eep command_string + SharedHelpers.run_shell_command(command_string).split("\n").filter_map do |line| info = line.split type = info.first @@ -881,7 +870,7 @@ def find_submodules(path) next path if type == DependencyFile::Mode::SUBMODULE end rescue SharedHelpers::HelperSubprocessFailed => spf - Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") if lfsEnabled + Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") if lfs_enabled Dependabot.logger.error(spf.message) raise end @@ -889,18 +878,18 @@ def find_submodules(path) sig { params(path: String).returns(T.nilable(T::Boolean)) } def isLfsEnabled(path) filepath = File.join(path,".gitattributes") - lfsEnabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include?("filter=lfs") + lfs_enabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include?("filter=lfs") rescue # this should not be needed, but I don't trust 'should' - lfsEnabled = T.let(false, T::Boolean) + lfs_enabled = T.let(false, T::Boolean) end - sig { params(path: String, lfsEnabled: T.nilable(T::Boolean)).returns(String) } - def getCommandString(path,lfsEnabled) - return "git -C #{path} ls-files --stage" unless lfsEnabled + sig { params(path: String, lfs_enabled: T.nilable(T::Boolean)).returns(String) } + def getCommandString(path,lfs_enabled) + return "git -C #{path} ls-files --stage" unless lfs_enabled Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") - commandString = "cd #{path};git-lfs ls-files --stage" - return commandString + command_string = "cd #{path};git-lfs ls-files --stage" + return command_string end end From 1fd1283af57a5c10c8a08ecd98299c97ab5e959f Mon Sep 17 00:00:00 2001 From: garryhurleyjr Date: Wed, 29 May 2024 23:24:57 -0400 Subject: [PATCH 16/20] lint fixes --- common/lib/dependabot/file_fetchers/base.rb | 33 +++++++++++---------- common/lib/dependabot/shared_helpers.rb | 12 ++++---- common/lib/dependabot/workspace/git.rb | 10 +++---- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/common/lib/dependabot/file_fetchers/base.rb b/common/lib/dependabot/file_fetchers/base.rb index 479ff5cdf1..cee5c1f9bb 100644 --- a/common/lib/dependabot/file_fetchers/base.rb +++ b/common/lib/dependabot/file_fetchers/base.rb @@ -824,7 +824,7 @@ def _clone_repo_contents(target_directory:) " --recurse-submodules=on-demand" end # Need to fetch the commit due to the --depth 1 above. - if isLfsEnabled(path.to_s) + if is_lfs_enabled(path.to_s) SharedHelpers.run_shell_command("git lfs install") SharedHelpers.run_shell_command("git-lfs-fetch #{fetch_options.string} origin #{source.commit}") else @@ -858,9 +858,9 @@ def decode_binary_string(str) sig { params(path: String).returns(T::Array[String]) } def find_submodules(path) - lfs_enabled = isLfsEnabled(path) if lfs_enabled.nil? + lfs_enabled = is_lfs_enabled(path) if lfs_enabled.nil? SharedHelpers.run_shell_command("git-lfs-checkout") if lfs_enabled - command_string = getCommandString(path,lfs_enabled) + command_string = get_command_string(path, lfs_enabled) # eep command_string SharedHelpers.run_shell_command(command_string).split("\n").filter_map do |line| info = line.split @@ -869,30 +869,31 @@ def find_submodules(path) path = T.must(info.last) next path if type == DependencyFile::Mode::SUBMODULE end - rescue SharedHelpers::HelperSubprocessFailed => spf + rescue SharedHelpers::HelperSubprocessFailed => e Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") if lfs_enabled - Dependabot.logger.error(spf.message) - raise + Dependabot.logger.error(e.message) + raise e.exception("Message: #{error.message}") end - + sig { params(path: String).returns(T.nilable(T::Boolean)) } - def isLfsEnabled(path) - filepath = File.join(path,".gitattributes") - lfs_enabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include?("filter=lfs") - rescue + def is_lfs_enabled(path) + filepath = File.join(path, ".gitattributes") + lfs_enabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) + && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include?("filter=lfs") + rescue Exception => e # this should not be needed, but I don't trust 'should' lfs_enabled = T.let(false, T::Boolean) + raise e end sig { params(path: String, lfs_enabled: T.nilable(T::Boolean)).returns(String) } - def getCommandString(path,lfs_enabled) + def get_command_string(path, lfs_enabled) return "git -C #{path} ls-files --stage" unless lfs_enabled Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") command_string = "cd #{path};git-lfs ls-files --stage" return command_string end - - end - end -end + end + end +end # rubocop:enable Metrics/ClassLength diff --git a/common/lib/dependabot/shared_helpers.rb b/common/lib/dependabot/shared_helpers.rb index 8e8acd2b07..dd601ce10b 100644 --- a/common/lib/dependabot/shared_helpers.rb +++ b/common/lib/dependabot/shared_helpers.rb @@ -374,11 +374,13 @@ def self.configure_git_to_use_https(host) sig { params(path: String).void } def self.reset_git_repo(path) - if isLfsEnabled(path) + if is_lfs_enabled(path) Dir.chdir(path) do - run_shell_command("git-lfs-reset HEAD --hard") + begin + run_shell_command("git-lfs-reset HEAD --hard") rescue SharedHelpers::HelperSubprocessFailed Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") + end run_shell_command("git clean -fx") end else @@ -390,12 +392,12 @@ def self.reset_git_repo(path) end sig { params(path: String).returns(T.nilable(T::Boolean)) } - def self.isLfsEnabled(path) + def self.is_lfs_enabled(path) filepath = File.join(path,".gitattributes") - lfsEnabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include?("filter=lfs") + lfs_enabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include?("filter=lfs") rescue # this should not be needed, but I don't trust 'should' - lfsEnabled = T.let(false, T::Boolean) + lfs_enabled = T.let(false, T::Boolean) end diff --git a/common/lib/dependabot/workspace/git.rb b/common/lib/dependabot/workspace/git.rb index 1d3dc278df..a3694835c0 100644 --- a/common/lib/dependabot/workspace/git.rb +++ b/common/lib/dependabot/workspace/git.rb @@ -13,7 +13,7 @@ class Git < Base USER = "dependabot[bot]" EMAIL = T.let("#{USER}@users.noreply.github.com".freeze, String) - lfsEnabled = nil + lfs_enabled = nil sig { returns(String) } attr_reader :initial_head_sha @@ -23,7 +23,7 @@ def initialize(path) super(path) @initial_head_sha = T.let(head_sha, String) configure_git - run_shell_command("git lfs install") if isLfsEnabled(path.to_s) + run_shell_command("git lfs install") if is_lfs_enabled(path.to_s) end sig { returns(T::Boolean) } @@ -172,12 +172,12 @@ def debug(message) end sig { params(path: String).returns(T.nilable(T::Boolean)) } - def isLfsEnabled(path) + def is_lfs_enabled(path) filepath = File.join(path,".gitattributes") - lfsEnabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include?("filter=lfs") + lfs_enabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include?("filter=lfs") rescue # this should not be needed, but I don't trust 'should' - lfsEnabled = T.let(false, T::Boolean) + lfs_enabled = T.let(false, T::Boolean) end end From 037657b2e117ca83931e2d4c7795e42d75740a66 Mon Sep 17 00:00:00 2001 From: garryhurleyjr Date: Wed, 29 May 2024 23:53:29 -0400 Subject: [PATCH 17/20] lint fixes --- common/lib/dependabot/file_fetchers/base.rb | 8 ++++---- common/lib/dependabot/shared_helpers.rb | 13 +++++++------ common/lib/dependabot/workspace/git.rb | 14 +++++++------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/common/lib/dependabot/file_fetchers/base.rb b/common/lib/dependabot/file_fetchers/base.rb index cee5c1f9bb..e886a04c66 100644 --- a/common/lib/dependabot/file_fetchers/base.rb +++ b/common/lib/dependabot/file_fetchers/base.rb @@ -872,18 +872,18 @@ def find_submodules(path) rescue SharedHelpers::HelperSubprocessFailed => e Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") if lfs_enabled Dependabot.logger.error(e.message) - raise e.exception("Message: #{error.message}") + raise e.exception("Message: #{e.message}") end sig { params(path: String).returns(T.nilable(T::Boolean)) } def is_lfs_enabled(path) filepath = File.join(path, ".gitattributes") - lfs_enabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) - && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include?("filter=lfs") + lfs_enabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && + SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include?("filter=lfs") rescue Exception => e # this should not be needed, but I don't trust 'should' lfs_enabled = T.let(false, T::Boolean) - raise e + raise e.exception("Message: #{e.message}") end sig { params(path: String, lfs_enabled: T.nilable(T::Boolean)).returns(String) } diff --git a/common/lib/dependabot/shared_helpers.rb b/common/lib/dependabot/shared_helpers.rb index dd601ce10b..32c3a8cbd2 100644 --- a/common/lib/dependabot/shared_helpers.rb +++ b/common/lib/dependabot/shared_helpers.rb @@ -374,7 +374,7 @@ def self.configure_git_to_use_https(host) sig { params(path: String).void } def self.reset_git_repo(path) - if is_lfs_enabled(path) + if lfs_enabled?(path) Dir.chdir(path) do begin run_shell_command("git-lfs-reset HEAD --hard") @@ -392,15 +392,16 @@ def self.reset_git_repo(path) end sig { params(path: String).returns(T.nilable(T::Boolean)) } - def self.is_lfs_enabled(path) - filepath = File.join(path,".gitattributes") - lfs_enabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include?("filter=lfs") - rescue + def self.lfs_enabled?(path) + filepath = File.join(path, ".gitattributes") + lfs_enabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && + SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include?("filter=lfs") + rescue Exception => e # this should not be needed, but I don't trust 'should' lfs_enabled = T.let(false, T::Boolean) + raise e.exception("Message: #{e.message}") end - sig { returns(T::Array[String]) } def self.find_safe_directories # to preserve safe directories from global .gitconfig diff --git a/common/lib/dependabot/workspace/git.rb b/common/lib/dependabot/workspace/git.rb index a3694835c0..56f4ee4e1e 100644 --- a/common/lib/dependabot/workspace/git.rb +++ b/common/lib/dependabot/workspace/git.rb @@ -13,7 +13,6 @@ class Git < Base USER = "dependabot[bot]" EMAIL = T.let("#{USER}@users.noreply.github.com".freeze, String) - lfs_enabled = nil sig { returns(String) } attr_reader :initial_head_sha @@ -23,7 +22,7 @@ def initialize(path) super(path) @initial_head_sha = T.let(head_sha, String) configure_git - run_shell_command("git lfs install") if is_lfs_enabled(path.to_s) + run_shell_command("git lfs install") if lfs_enabled?(path.to_s) end sig { returns(T::Boolean) } @@ -172,14 +171,15 @@ def debug(message) end sig { params(path: String).returns(T.nilable(T::Boolean)) } - def is_lfs_enabled(path) - filepath = File.join(path,".gitattributes") - lfs_enabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include?("filter=lfs") - rescue + def lfs_enabled?(path) + filepath = File.join(path, ".gitattributes") + lfs_enabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && + SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include?("filter=lfs") + rescue Exception => e # this should not be needed, but I don't trust 'should' lfs_enabled = T.let(false, T::Boolean) + raise e.exception("Message: #{e.message}") end - end end end From f079add6febe039512da0a6784a9bcbacb5f31b4 Mon Sep 17 00:00:00 2001 From: garryhurleyjr Date: Thu, 30 May 2024 08:48:10 -0400 Subject: [PATCH 18/20] lint fixes --- common/lib/dependabot/file_fetchers/base.rb | 17 +++++++++-------- common/lib/dependabot/shared_helpers.rb | 11 ++++++----- common/lib/dependabot/workspace/git.rb | 11 ++++++----- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/common/lib/dependabot/file_fetchers/base.rb b/common/lib/dependabot/file_fetchers/base.rb index e886a04c66..cc5f7b59f8 100644 --- a/common/lib/dependabot/file_fetchers/base.rb +++ b/common/lib/dependabot/file_fetchers/base.rb @@ -824,7 +824,7 @@ def _clone_repo_contents(target_directory:) " --recurse-submodules=on-demand" end # Need to fetch the commit due to the --depth 1 above. - if is_lfs_enabled(path.to_s) + if lfs_enabled?(path.to_s) SharedHelpers.run_shell_command("git lfs install") SharedHelpers.run_shell_command("git-lfs-fetch #{fetch_options.string} origin #{source.commit}") else @@ -858,7 +858,7 @@ def decode_binary_string(str) sig { params(path: String).returns(T::Array[String]) } def find_submodules(path) - lfs_enabled = is_lfs_enabled(path) if lfs_enabled.nil? + lfs_enabled = lfs_enabled?(path) if lfs_enabled.nil? SharedHelpers.run_shell_command("git-lfs-checkout") if lfs_enabled command_string = get_command_string(path, lfs_enabled) # eep command_string @@ -876,14 +876,15 @@ def find_submodules(path) end sig { params(path: String).returns(T.nilable(T::Boolean)) } - def is_lfs_enabled(path) + def lfs_enabled?(path) filepath = File.join(path, ".gitattributes") - lfs_enabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && - SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include?("filter=lfs") - rescue Exception => e + return T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && + SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"") + .include?("filter=lfs") + rescue StandardError => e + Dependabot.logger.warn("An error has occurred: #{e.message}") # this should not be needed, but I don't trust 'should' - lfs_enabled = T.let(false, T::Boolean) - raise e.exception("Message: #{e.message}") + return T.let(false, T::Boolean) end sig { params(path: String, lfs_enabled: T.nilable(T::Boolean)).returns(String) } diff --git a/common/lib/dependabot/shared_helpers.rb b/common/lib/dependabot/shared_helpers.rb index 32c3a8cbd2..bfb0d5eca7 100644 --- a/common/lib/dependabot/shared_helpers.rb +++ b/common/lib/dependabot/shared_helpers.rb @@ -394,12 +394,13 @@ def self.reset_git_repo(path) sig { params(path: String).returns(T.nilable(T::Boolean)) } def self.lfs_enabled?(path) filepath = File.join(path, ".gitattributes") - lfs_enabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && - SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include?("filter=lfs") - rescue Exception => e + return T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && + SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"") + .include?("filter=lfs") + rescue StandardError => e + Dependabot.logger.warn("An error occurred: #{e.message}") # this should not be needed, but I don't trust 'should' - lfs_enabled = T.let(false, T::Boolean) - raise e.exception("Message: #{e.message}") + return T.let(false, T::Boolean) end sig { returns(T::Array[String]) } diff --git a/common/lib/dependabot/workspace/git.rb b/common/lib/dependabot/workspace/git.rb index 56f4ee4e1e..c47bbd092a 100644 --- a/common/lib/dependabot/workspace/git.rb +++ b/common/lib/dependabot/workspace/git.rb @@ -173,12 +173,13 @@ def debug(message) sig { params(path: String).returns(T.nilable(T::Boolean)) } def lfs_enabled?(path) filepath = File.join(path, ".gitattributes") - lfs_enabled = T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && - SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"").include?("filter=lfs") - rescue Exception => e + return T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && + SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"") + .include?("filter=lfs") + rescue StandardError => e + Dependabot.logger.warn("An error has occurred: #{e.message}") # this should not be needed, but I don't trust 'should' - lfs_enabled = T.let(false, T::Boolean) - raise e.exception("Message: #{e.message}") + return T.let(false, T::Boolean) end end end From 5f555ef75c32b462e59701942d040cf62bb0d244 Mon Sep 17 00:00:00 2001 From: garryhurleyjr Date: Thu, 30 May 2024 08:54:54 -0400 Subject: [PATCH 19/20] lint fixes --- common/spec/dependabot/file_fetchers/base_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/spec/dependabot/file_fetchers/base_spec.rb b/common/spec/dependabot/file_fetchers/base_spec.rb index be3364b3f7..b7f4d30bdb 100644 --- a/common/spec/dependabot/file_fetchers/base_spec.rb +++ b/common/spec/dependabot/file_fetchers/base_spec.rb @@ -1643,7 +1643,7 @@ def fetch_files end end - context "when a retryable error occurs", focus: true do + context "when a retryable error occurs" do let(:retryable_error) do proc { raise Dependabot::SharedHelpers::HelperSubprocessFailed.new( From b5ec97ba0cdec7ffa2604286c29362b754fd4ac7 Mon Sep 17 00:00:00 2001 From: garryhurleyjr Date: Thu, 30 May 2024 09:37:34 -0400 Subject: [PATCH 20/20] lint fixes --- common/lib/dependabot/file_fetchers/base.rb | 10 +++++----- common/lib/dependabot/shared_helpers.rb | 8 ++++---- common/lib/dependabot/workspace/git.rb | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/common/lib/dependabot/file_fetchers/base.rb b/common/lib/dependabot/file_fetchers/base.rb index cc5f7b59f8..de8ef26591 100644 --- a/common/lib/dependabot/file_fetchers/base.rb +++ b/common/lib/dependabot/file_fetchers/base.rb @@ -878,21 +878,21 @@ def find_submodules(path) sig { params(path: String).returns(T.nilable(T::Boolean)) } def lfs_enabled?(path) filepath = File.join(path, ".gitattributes") - return T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && + T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"") - .include?("filter=lfs") + .include?("filter=lfs") rescue StandardError => e Dependabot.logger.warn("An error has occurred: #{e.message}") # this should not be needed, but I don't trust 'should' - return T.let(false, T::Boolean) + T.let(false, T::Boolean) end sig { params(path: String, lfs_enabled: T.nilable(T::Boolean)).returns(String) } def get_command_string(path, lfs_enabled) return "git -C #{path} ls-files --stage" unless lfs_enabled + Dependabot.logger.warn("LFS is enabled in this repo. Please use an LFS enabled client") - command_string = "cd #{path};git-lfs ls-files --stage" - return command_string + return "cd #{path};git-lfs ls-files --stage" end end end diff --git a/common/lib/dependabot/shared_helpers.rb b/common/lib/dependabot/shared_helpers.rb index bfb0d5eca7..d5dd418f5a 100644 --- a/common/lib/dependabot/shared_helpers.rb +++ b/common/lib/dependabot/shared_helpers.rb @@ -374,7 +374,7 @@ def self.configure_git_to_use_https(host) sig { params(path: String).void } def self.reset_git_repo(path) - if lfs_enabled?(path) + if lfs_enabled?(path) Dir.chdir(path) do begin run_shell_command("git-lfs-reset HEAD --hard") @@ -394,13 +394,13 @@ def self.reset_git_repo(path) sig { params(path: String).returns(T.nilable(T::Boolean)) } def self.lfs_enabled?(path) filepath = File.join(path, ".gitattributes") - return T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && + T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"") - .include?("filter=lfs") + .include?("filter=lfs") rescue StandardError => e Dependabot.logger.warn("An error occurred: #{e.message}") # this should not be needed, but I don't trust 'should' - return T.let(false, T::Boolean) + T.let(false, T::Boolean) end sig { returns(T::Array[String]) } diff --git a/common/lib/dependabot/workspace/git.rb b/common/lib/dependabot/workspace/git.rb index c47bbd092a..714cc5a6b2 100644 --- a/common/lib/dependabot/workspace/git.rb +++ b/common/lib/dependabot/workspace/git.rb @@ -173,13 +173,13 @@ def debug(message) sig { params(path: String).returns(T.nilable(T::Boolean)) } def lfs_enabled?(path) filepath = File.join(path, ".gitattributes") - return T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && + T.let(true, T::Boolean) if File.exist?(filepath) && File.readable?(filepath) && SharedHelpers.run_shell_command("cat #{filepath} | grep \"filter=lfs\"") - .include?("filter=lfs") + .include?("filter=lfs") rescue StandardError => e Dependabot.logger.warn("An error has occurred: #{e.message}") # this should not be needed, but I don't trust 'should' - return T.let(false, T::Boolean) + T.let(false, T::Boolean) end end end