Fix regression: can fetch branches and tags references without specifying commit hashes for private git repository used as context (#1823)
* [FIX] can fetch tags and branches refs without specifying commit hashes * [ENH] more precise comment
This commit is contained in:
parent
e38b0c8d90
commit
d2f3e896cd
|
|
@ -68,11 +68,19 @@ func (g *Git) UnpackTarFromBuildContext() (string, error) {
|
||||||
RecurseSubmodules: getRecurseSubmodules(g.opts.GitRecurseSubmodules),
|
RecurseSubmodules: getRecurseSubmodules(g.opts.GitRecurseSubmodules),
|
||||||
}
|
}
|
||||||
var fetchRef string
|
var fetchRef string
|
||||||
|
var checkoutRef string
|
||||||
if len(parts) > 1 {
|
if len(parts) > 1 {
|
||||||
if plumbing.IsHash(parts[1]) || !strings.HasPrefix(parts[1], "refs/pull/") {
|
if plumbing.IsHash(parts[1]) || !strings.HasPrefix(parts[1], "refs/pull/") {
|
||||||
// Handle any non-branch refs separately. First, clone the repo HEAD, and
|
// Handle any non-branch refs separately. First, clone the repo HEAD, and
|
||||||
// then fetch and check out the fetchRef.
|
// then fetch and check out the fetchRef.
|
||||||
fetchRef = parts[1]
|
fetchRef = parts[1]
|
||||||
|
if plumbing.IsHash(parts[1]) {
|
||||||
|
checkoutRef = fetchRef
|
||||||
|
} else {
|
||||||
|
// The ReferenceName still needs to be present in the options passed
|
||||||
|
// to the clone operation for non-hash references of private repositories.
|
||||||
|
options.ReferenceName = plumbing.ReferenceName(fetchRef)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Branches will be cloned directly.
|
// Branches will be cloned directly.
|
||||||
options.ReferenceName = plumbing.ReferenceName(parts[1])
|
options.ReferenceName = plumbing.ReferenceName(parts[1])
|
||||||
|
|
@ -104,7 +112,6 @@ func (g *Git) UnpackTarFromBuildContext() (string, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkoutRef := fetchRef
|
|
||||||
if len(parts) > 2 {
|
if len(parts) > 2 {
|
||||||
checkoutRef = parts[2]
|
checkoutRef = parts[2]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue