From d6ede083eb8ca7bdf83f7735d095bccca14ccb64 Mon Sep 17 00:00:00 2001 From: Paul Berruti Date: Wed, 30 Oct 2024 07:05:18 -0700 Subject: [PATCH] Fix git add command to handle paths with spaces This probably doesn't entirely address #10527 but may be related. See also #8633. --- common/lib/dependabot/workspace/git.rb | 2 +- common/spec/dependabot/workspace/git_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common/lib/dependabot/workspace/git.rb b/common/lib/dependabot/workspace/git.rb index 98114e4f011..58a128454df 100644 --- a/common/lib/dependabot/workspace/git.rb +++ b/common/lib/dependabot/workspace/git.rb @@ -133,7 +133,7 @@ def stash(memo = nil) sig { params(memo: T.nilable(String)).returns([String, String]) } def commit(memo = nil) - run_shell_command("git add #{path}") + run_shell_command(%(git add "#{path}"), allow_unsafe_shell_command: true) diff = run_shell_command("git diff --cached .") msg = memo || "workspace change" diff --git a/common/spec/dependabot/workspace/git_spec.rb b/common/spec/dependabot/workspace/git_spec.rb index 3388bc9d4e6..b4428cb0f17 100644 --- a/common/spec/dependabot/workspace/git_spec.rb +++ b/common/spec/dependabot/workspace/git_spec.rb @@ -10,7 +10,7 @@ RSpec.describe Dependabot::Workspace::Git do subject(:workspace) { described_class.new(repo_contents_path) } - let(:repo_contents_path) { build_tmp_repo("simple", tmp_dir_path: Dir.tmpdir) } + let(:repo_contents_path) { build_tmp_repo("simple", tmp_dir_path: File.join(Dir.tmpdir, "with space")) } around do |example| Dir.chdir(repo_contents_path) { example.run }