Skip to content

Commit

Permalink
Move path manipulation out of the Workspace::Git class
Browse files Browse the repository at this point in the history
  • Loading branch information
brrygrdn committed Jun 26, 2023
1 parent cabfe2e commit 37d48ed
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
3 changes: 3 additions & 0 deletions common/lib/dependabot/shared_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ module SharedHelpers

def self.in_a_temporary_repo_directory(directory = "/", repo_contents_path = nil, &block)
if repo_contents_path
# If a workspace has been defined to allow orcestration of the git repo
# by the runtime we should defer to it, otherwise we prepare the folder
# for direct use and yield.
if Dependabot::Workspace.active_workspace
Dependabot::Workspace.active_workspace.change(&block)
else
Expand Down
10 changes: 6 additions & 4 deletions common/lib/dependabot/workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ class << self
def self.setup(repo_contents_path:, directory:)
Dependabot.logger.debug("Setting up workspace in #{repo_contents_path}")

@active_workspace = Dependabot::Workspace::Git.new(
repo_contents_path,
Pathname.new(directory || "/").cleanpath
)
full_path = Pathname.new(File.join(repo_contents_path, directory)).expand_path
# Handle missing directories by creating an empty one and relying on the
# file fetcher to raise a DependencyFileNotFound error
FileUtils.mkdir_p(full_path)

@active_workspace = Dependabot::Workspace::Git.new(full_path)
end

def self.store_change(memo:)
Expand Down
17 changes: 8 additions & 9 deletions common/lib/dependabot/workspace/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@ class Git < Base

attr_reader :initial_head_sha

def initialize(repo_contents_path, directory = "/")
full_path = Pathname.new(File.join(repo_contents_path, directory)).expand_path
# Handle missing directories by creating an empty one and relying on the
# file fetcher to raise a DependencyFileNotFound error
FileUtils.mkdir_p(full_path)
super(full_path)
def initialize(path)
super(path)
@initial_head_sha = head_sha

run_shell_command(%(git config user.name "#{USER}"), allow_unsafe_shell_command: true)
run_shell_command(%(git config user.email "#{EMAIL}"), allow_unsafe_shell_command: true)
configure_git
end

def to_patch
Expand Down Expand Up @@ -57,6 +51,11 @@ def capture_failed_change_attempt(memo = nil, error = nil)

private

def configure_git
run_shell_command(%(git config user.name "#{USER}"), allow_unsafe_shell_command: true)
run_shell_command(%(git config user.email "#{EMAIL}"), allow_unsafe_shell_command: true)
end

def head_sha
run_shell_command("git rev-parse HEAD").strip
end
Expand Down

0 comments on commit 37d48ed

Please sign in to comment.