fix: Allow specifying :revision for resources downloaded from Git repos whose default branch is not named master

### Background
Given a repo that does not have branch named `master` and a formula like this:
```ruby
class Example < Formula
  stable do
    url "https://github.com/user/example.git", revision: "e8b123de62e0faec283c3253c6ea5495a332007e"
  end
end
```

Homebrew was executing this when the cached location did not exist:
```
git clone https://github.com/user/example.git /path/to/cache
```
(which would work)

and this when the cached location did exist:
```
git -C /path/to/cache config remote.origin.fetch +refs/heads/master:refs/remotes/origin/master
git -C /path/to/cache fetch origin
```
(which would always fail with `fatal: couldn't find remote ref refs/heads/master`)

This commit changes the value for `remote.origin.fetch` to `+refs/heads/*:refs/remotes/origin/*` which is [Git's default value for the refspec](https://git-scm.com/book/en/v2/Git-Internals-The-Refspec) anyway.

This may increase the latency of `git fetch origin` for formulae that use `:revision` because Git will now fetch all remote refs; but it does have the advantage of not being broken 🙂
This commit is contained in:
Bob Lail 2021-10-22 10:38:52 -05:00
parent 55285e29b1
commit 701a1661d2

View File

@ -897,7 +897,7 @@ class GitDownloadStrategy < VCSDownloadStrategy
case @ref_type
when :branch then "+refs/heads/#{@ref}:refs/remotes/origin/#{@ref}"
when :tag then "+refs/tags/#{@ref}:refs/tags/#{@ref}"
else "+refs/heads/master:refs/remotes/origin/master"
else "+refs/heads/*:refs/remotes/origin/*"
end
end