Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regression: can fetch branches and tags references without specifying commit hashes for private git repository used as context #1823

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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