Skip to content

Commit

Permalink
Always use git metatada when fetching the latest commit information
Browse files Browse the repository at this point in the history
Since we're now able to bump both refs and versions (in comments) at the
same time, `dependency.version` may not always hold a ref now. So always
rely on metadata here.
  • Loading branch information
deivid-rodriguez committed Nov 11, 2022
1 parent 81d2e21 commit 5533448
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
9 changes: 2 additions & 7 deletions common/lib/dependabot/git_commit_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,8 @@ def branch_or_ref_in_release?(version)
def head_commit_for_current_branch
ref = ref_or_branch || "HEAD"

if pinned?
return dependency.version ||
local_repo_git_metadata_fetcher.head_commit_for_ref(ref)
end

sha = local_repo_git_metadata_fetcher.head_commit_for_ref(ref)
return sha if sha
sha = head_commit_for_local_branch(ref)
return sha if pinned? || sha

raise Dependabot::GitDependencyReferenceNotFound, dependency.name
end
Expand Down
41 changes: 21 additions & 20 deletions common/spec/dependabot/git_commit_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -510,31 +510,32 @@
ref: "v1.0.0"
}
end
it { is_expected.to eq(dependency.version) }

context "without a version" do
let(:version) { nil }
let(:git_header) do
{ "content-type" => "application/x-git-upload-pack-advertisement" }
end
let(:auth_header) { "Basic eC1hY2Nlc3MtdG9rZW46dG9rZW4=" }

let(:git_header) do
{ "content-type" => "application/x-git-upload-pack-advertisement" }
end
let(:auth_header) { "Basic eC1hY2Nlc3MtdG9rZW46dG9rZW4=" }
let(:git_url) do
"https://github.com/gocardless/business.git" \
"/info/refs?service=git-upload-pack"
end

let(:git_url) do
"https://github.com/gocardless/business.git" \
"/info/refs?service=git-upload-pack"
context "that can be reached just fine" do
before do
stub_request(:get, git_url).
with(headers: { "Authorization" => auth_header }).
to_return(
status: 200,
body: fixture("git", "upload_packs", "business"),
headers: git_header
)
end

context "that can be reached just fine" do
before do
stub_request(:get, git_url).
with(headers: { "Authorization" => auth_header }).
to_return(
status: 200,
body: fixture("git", "upload_packs", "business"),
headers: git_header
)
end
it { is_expected.to eq(dependency.version) }

context "without a version" do
let(:version) { nil }

it { is_expected.to eq("df9f605d7111b6814fe493cf8f41de3f9f0978b2") }

Expand Down

0 comments on commit 5533448

Please sign in to comment.