Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when updating git dependencies #5934

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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