Skip to content

Commit

Permalink
Fix regression: can fetch branches and tags references without specif…
Browse files Browse the repository at this point in the history
…ying 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
  • Loading branch information
gcalmettes authored Dec 24, 2021
1 parent e38b0c8 commit d2f3e89
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/buildcontext/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,19 @@ func (g *Git) UnpackTarFromBuildContext() (string, error) {
RecurseSubmodules: getRecurseSubmodules(g.opts.GitRecurseSubmodules),
}
var fetchRef string
var checkoutRef string
if len(parts) > 1 {
if plumbing.IsHash(parts[1]) || !strings.HasPrefix(parts[1], "refs/pull/") {
// Handle any non-branch refs separately. First, clone the repo HEAD, and
// then fetch and check out the fetchRef.
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 {
// Branches will be cloned directly.
options.ReferenceName = plumbing.ReferenceName(parts[1])
Expand Down Expand Up @@ -104,7 +112,6 @@ func (g *Git) UnpackTarFromBuildContext() (string, error) {
}
}

checkoutRef := fetchRef
if len(parts) > 2 {
checkoutRef = parts[2]
}
Expand Down

0 comments on commit d2f3e89

Please sign in to comment.