Skip to content

Commit

Permalink
Merge pull request #5937 from dependabot/jakecoffman/fix-race-and-tes…
Browse files Browse the repository at this point in the history
…ting-local

fix race and updating local mounted repositories
  • Loading branch information
jakecoffman authored Oct 24, 2022
2 parents 417a6c3 + ba7dcdc commit b49c206
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 466 deletions.
11 changes: 11 additions & 0 deletions common/lib/dependabot/file_fetchers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def files
end

def commit
return cloned_commit if cloned_commit
return source.commit if source.commit

branch = target_branch || default_branch_for_repo
Expand Down Expand Up @@ -473,6 +474,16 @@ def _fetch_file_content_from_github(path, repo, commit)
end
# rubocop:enable Metrics/AbcSize

def cloned_commit
return if repo_contents_path.nil? || !File.directory?(File.join(repo_contents_path, ".git"))

SharedHelpers.with_git_configured(credentials: credentials) do
Dir.chdir(repo_contents_path) do
return SharedHelpers.run_shell_command("git rev-parse HEAD")&.strip
end
end
end

def default_branch_for_repo
@default_branch_for_repo ||= client_for_provider.
fetch_default_branch(repo)
Expand Down
6 changes: 4 additions & 2 deletions updater/lib/dependabot/file_fetcher_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class FileFetcherJob < BaseJob
def perform_job
begin
connectivity_check if ENV["ENABLE_CONNECTIVITY_CHECK"] == "1"
clone_repo_contents
base_commit_sha
dependency_files
clone_repo_contents
rescue StandardError => e
if Octokit::RATE_LIMITED_ERRORS.include?(e.class)
remaining = rate_limit_error_remaining(e)
Expand Down Expand Up @@ -94,12 +94,14 @@ def base_commit_sha
end

def file_fetcher
return @file_fetcher if defined? @file_fetcher

args = {
source: job.source,
credentials: job_definition.fetch("credentials", []),
options: job.experiments
}
args[:repo_contents_path] = Environment.repo_contents_path if job.clone?
args[:repo_contents_path] = Environment.repo_contents_path if job.clone? || job.already_cloned?
@file_fetcher ||=
Dependabot::FileFetchers.for_package_manager(job.package_manager).
new(**args)
Expand Down
7 changes: 7 additions & 0 deletions updater/lib/dependabot/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ def clone?
Dependabot::Utils.always_clone_for_package_manager?(@package_manager)
end

def already_cloned?
return unless Environment.repo_contents_path

# For testing, the source repo may already be mounted.
@already_cloned ||= File.directory?(File.join(Environment.repo_contents_path, ".git"))
end

def lockfile_only?
@lockfile_only
end
Expand Down

This file was deleted.

Loading

0 comments on commit b49c206

Please sign in to comment.