Merge pull request #12304 from boblail/fix-git-download-with-revision
fix: Allow specifying `:revision` for resources downloaded from Git repos whose default branch is not named `master`
This commit is contained in:
commit
919f9d45b1
@ -897,10 +897,16 @@ class GitDownloadStrategy < VCSDownloadStrategy
|
|||||||
case @ref_type
|
case @ref_type
|
||||||
when :branch then "+refs/heads/#{@ref}:refs/remotes/origin/#{@ref}"
|
when :branch then "+refs/heads/#{@ref}:refs/remotes/origin/#{@ref}"
|
||||||
when :tag then "+refs/tags/#{@ref}:refs/tags/#{@ref}"
|
when :tag then "+refs/tags/#{@ref}:refs/tags/#{@ref}"
|
||||||
else "+refs/heads/master:refs/remotes/origin/master"
|
else default_refspec
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(String) }
|
||||||
|
def default_refspec
|
||||||
|
# https://git-scm.com/book/en/v2/Git-Internals-The-Refspec
|
||||||
|
"+refs/heads/*:refs/remotes/origin/*"
|
||||||
|
end
|
||||||
|
|
||||||
sig { void }
|
sig { void }
|
||||||
def config_repo
|
def config_repo
|
||||||
command! "git",
|
command! "git",
|
||||||
@ -1069,6 +1075,30 @@ class GitHubGitDownloadStrategy < GitDownloadStrategy
|
|||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(String) }
|
||||||
|
def default_refspec
|
||||||
|
if default_branch
|
||||||
|
"+refs/heads/#{default_branch}:refs/remotes/origin/#{default_branch}"
|
||||||
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
sig { returns(String) }
|
||||||
|
def default_branch
|
||||||
|
return @default_branch if defined?(@default_branch)
|
||||||
|
|
||||||
|
command! "git",
|
||||||
|
args: ["remote", "set-head", "origin", "--auto"],
|
||||||
|
chdir: cached_location
|
||||||
|
|
||||||
|
result = command! "git",
|
||||||
|
args: ["symbolic-ref", "refs/remotes/origin/HEAD"],
|
||||||
|
chdir: cached_location
|
||||||
|
|
||||||
|
@default_branch = result.stdout[%r{^refs/remotes/origin/(.*)$}, 1]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Strategy for downloading a CVS repository.
|
# Strategy for downloading a CVS repository.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user