From c08e96dfe11a5d362f3597420f3131474e4a78d6 Mon Sep 17 00:00:00 2001 From: Jake Coffman Date: Wed, 15 Jan 2025 09:07:47 -0600 Subject: [PATCH 1/2] fix timeouts caused by stashing large failed changes --- .../dependabot/workspace/change_attempt.rb | 5 --- common/lib/dependabot/workspace/git.rb | 14 +++----- common/spec/dependabot/workspace/git_spec.rb | 33 ------------------- 3 files changed, 4 insertions(+), 48 deletions(-) diff --git a/common/lib/dependabot/workspace/change_attempt.rb b/common/lib/dependabot/workspace/change_attempt.rb index 74a20a1890..e97d426add 100644 --- a/common/lib/dependabot/workspace/change_attempt.rb +++ b/common/lib/dependabot/workspace/change_attempt.rb @@ -8,9 +8,6 @@ module Workspace class ChangeAttempt extend T::Sig - sig { returns(T.nilable(String)) } - attr_reader :diff - sig { returns(T.nilable(StandardError)) } attr_reader :error @@ -28,7 +25,6 @@ class ChangeAttempt workspace: Dependabot::Workspace::Base, id: String, memo: T.nilable(String), - diff: T.nilable(String), error: T.nilable(StandardError) ).void end @@ -36,7 +32,6 @@ def initialize(workspace, id:, memo:, diff: nil, error: nil) @workspace = workspace @id = id @memo = memo - @diff = diff @error = error end diff --git a/common/lib/dependabot/workspace/git.rb b/common/lib/dependabot/workspace/git.rb index fcef52094e..28a6b63554 100644 --- a/common/lib/dependabot/workspace/git.rb +++ b/common/lib/dependabot/workspace/git.rb @@ -73,8 +73,8 @@ def store_change(memo = nil) def capture_failed_change_attempt(memo = nil, error = nil) return nil if changed_files(ignored_mode: "matching").empty? && error.nil? - sha, diff = stash(memo) - change_attempts << ChangeAttempt.new(self, id: sha, memo: memo, diff: diff, error: error) + sha = stash(memo) + change_attempts << ChangeAttempt.new(self, id: sha, memo: memo, error: error) end private @@ -112,7 +112,7 @@ def changed_files(ignored_mode: "traditional") ).strip end - sig { params(memo: T.nilable(String)).returns([String, String]) } + sig { params(memo: T.nilable(String)).returns(String) } def stash(memo = nil) msg = memo || "workspace change attempt" run_shell_command("git add --all --force .") @@ -122,13 +122,7 @@ def stash(memo = nil) allow_unsafe_shell_command: true ) - sha = last_stash_sha - diff = run_shell_command( - "git stash show --patch #{sha}", - fingerprint: "git stash show --patch " - ) - - [sha, diff] + last_stash_sha end sig { params(memo: T.nilable(String)).returns([String, String]) } diff --git a/common/spec/dependabot/workspace/git_spec.rb b/common/spec/dependabot/workspace/git_spec.rb index ee82fe0d5f..efa8bd7d75 100644 --- a/common/spec/dependabot/workspace/git_spec.rb +++ b/common/spec/dependabot/workspace/git_spec.rb @@ -61,17 +61,6 @@ workspace.store_change("rspec") end - it "returns the diff of all changes" do - expect(workspace.changes.size).to eq(2) - expect(workspace.to_patch).to end_with( - <<~DIFF - gem "activesupport", ">= 6.0.0" - +gem "rspec", "~> 3.12.0", group: :test - +gem "timecop", "~> 0.9.6", group: :test - DIFF - ) - end - context "when there are failed change attempts" do before do workspace.change("fail") do @@ -123,12 +112,6 @@ expect(workspace.failed_change_attempts.size).to eq(1) expect(workspace.change_attempts.size).to eq(1) expect(workspace.change_attempts.first.id).to eq(`git rev-parse refs/stash`.strip) - expect(workspace.change_attempts.first.diff).to end_with( - <<~DIFF - gem "activesupport", ">= 6.0.0" - +gem "timecop", "~> 0.9.6", group: :test - DIFF - ) expect(workspace.change_attempts.first.memo).to eq("timecop") expect(workspace.change_attempts.first.error).not_to be_nil expect(workspace.change_attempts.first.error.message).to eq("uh oh") @@ -152,16 +135,6 @@ it "captures the untracked/ignored files" do expect(workspace.failed_change_attempts.size).to eq(1) - expect(workspace.failed_change_attempts.first.diff).to include( - <<~DIFF - gem "activesupport", ">= 6.0.0" - +gem "fail" - DIFF - ) - expect(workspace.failed_change_attempts.first.diff).to include( - "diff --git a/ignored-file.txt b/ignored-file.txt", - "diff --git a/untracked-file.txt b/untracked-file.txt" - ) end end end @@ -253,12 +226,6 @@ expect(workspace).to be_changed expect(workspace.change_attempts.size).to eq(1) expect(workspace.change_attempts.first.id).to eq(`git rev-parse HEAD`.strip) - expect(workspace.change_attempts.first.diff).to end_with( - <<~DIFF - gem "activesupport", ">= 6.0.0" - +gem "timecop", "~> 0.9.6", group: :test - DIFF - ) expect(workspace.change_attempts.first.memo).to eq("Update timecop") expect(workspace.change_attempts.first.error).to be_nil expect(workspace.change_attempts.first).not_to be_error From fb787b5111d45ce50e3a09148cc106feeb2771bb Mon Sep 17 00:00:00 2001 From: Jake Coffman Date: Wed, 15 Jan 2025 09:17:38 -0600 Subject: [PATCH 2/2] remove more diffs --- common/lib/dependabot/workspace/change_attempt.rb | 2 +- common/lib/dependabot/workspace/git.rb | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/common/lib/dependabot/workspace/change_attempt.rb b/common/lib/dependabot/workspace/change_attempt.rb index e97d426add..af111a3eb2 100644 --- a/common/lib/dependabot/workspace/change_attempt.rb +++ b/common/lib/dependabot/workspace/change_attempt.rb @@ -28,7 +28,7 @@ class ChangeAttempt error: T.nilable(StandardError) ).void end - def initialize(workspace, id:, memo:, diff: nil, error: nil) + def initialize(workspace, id:, memo:, error: nil) @workspace = workspace @id = id @memo = memo diff --git a/common/lib/dependabot/workspace/git.rb b/common/lib/dependabot/workspace/git.rb index 28a6b63554..2b781ebe72 100644 --- a/common/lib/dependabot/workspace/git.rb +++ b/common/lib/dependabot/workspace/git.rb @@ -56,9 +56,9 @@ def store_change(memo = nil) return nil if changed_files(ignored_mode: "no").empty? debug("store_change - before: #{current_commit}") - sha, diff = commit(memo) + sha = commit(memo) - change_attempts << ChangeAttempt.new(self, id: sha, memo: memo, diff: diff) + change_attempts << ChangeAttempt.new(self, id: sha, memo: memo) ensure debug("store_change - after: #{current_commit}") end @@ -125,10 +125,9 @@ def stash(memo = nil) last_stash_sha end - sig { params(memo: T.nilable(String)).returns([String, String]) } + sig { params(memo: T.nilable(String)).returns(String) } def commit(memo = nil) run_shell_command("git add #{path}") - diff = run_shell_command("git diff --cached .") msg = memo || "workspace change" run_shell_command( @@ -137,7 +136,7 @@ def commit(memo = nil) allow_unsafe_shell_command: true ) - [head_sha, diff] + head_sha end sig { params(sha: String).returns(String) }