Skip to content

Commit

Permalink
Fix crash when updating git dependencies
Browse files Browse the repository at this point in the history
If there's an evaled gemfile that also includes git dependencies, it
would result in a crash like the following:

```
Failure/Error:
  dependency.requirements.
  find { |f| f[:file] == file.name }.
  fetch(:source).fetch(:ref)

NoMethodError:
  undefined method `fetch' for nil:NilClass

              fetch(:source).fetch(:ref)
```

We need to check the Gemfile name being updated, not generic names when
figuring out if we should update any git pins.
  • Loading branch information
deivid-rodriguez committed Oct 20, 2022
1 parent 508536b commit 3a8bfc1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def updated_gemfile_content

content = remove_gemfile_git_source(dependency, content) if remove_git_source?(dependency)

content = update_gemfile_git_pin(dependency, gemfile, content) if update_git_pin?(dependency)
content = update_gemfile_git_pin(dependency, gemfile, content) if update_git_pin?(dependency, gemfile)
end

content
Expand Down Expand Up @@ -81,10 +81,10 @@ def remove_git_source?(dependency)
new_gemfile_req[:source].nil?
end

def update_git_pin?(dependency)
def update_git_pin?(dependency, file)
new_gemfile_req =
dependency.requirements.
find { |f| GEMFILE_FILENAMES.include?(f[:file]) }
find { |f| f[:file] == file.name }
return false unless new_gemfile_req&.dig(:source, :type) == "git"

# If the new requirement is a git dependency with a ref then there's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,20 @@
end

it { is_expected.to eq(expected_string) }

context "but updating an evaled gemfile including a different git sourced dependency" do
let(:gemfile_body) do
%(gem "dependabot-test-other", git: "https://github.com/dependabot-fixtures/dependabot-other")
end

let(:gemfile) do
Dependabot::DependencyFile.new(content: gemfile_body, name: "Gemfile.included")
end

it "leaves the evaled gemfile untouched" do
is_expected.to eq(gemfile_body)
end
end
end

context "that should be removed" do
Expand Down

0 comments on commit 3a8bfc1

Please sign in to comment.