Skip to content

allow an explicit git ref to be passed so we can checkout any ref regardless of the git url #409

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type CloneRepoOptions struct {

RepoURL string
RepoAuth transport.AuthMethod
GitRef string
Progress sideband.Progress
Insecure bool
SingleBranch bool
Expand Down Expand Up @@ -84,6 +85,8 @@ func CloneRepo(ctx context.Context, logf func(string, ...any), opts CloneRepoOpt
reference := parsed.Fragment
if reference == "" && opts.SingleBranch {
reference = "refs/heads/main"
} else if reference == "" && opts.GitRef != "" {
reference = opts.GitRef
}
parsed.RawFragment = ""
parsed.Fragment = ""
Expand Down Expand Up @@ -343,6 +346,7 @@ func CloneOptionsFromOptions(logf func(string, ...any), options options.Options)

cloneOpts := CloneRepoOptions{
RepoURL: options.GitURL,
GitRef: options.GitRef,
Path: options.WorkspaceFolder,
Storage: options.Filesystem,
Insecure: options.Insecure,
Expand Down
8 changes: 8 additions & 0 deletions options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ type Options struct {
GitSSHPrivateKeyBase64 string
// GitHTTPProxyURL is the URL for the HTTP proxy. This is optional.
GitHTTPProxyURL string
// GitRef is the git ref to checkout after clone. This is optional.
GitRef string
// WorkspaceFolder is the path to the workspace folder that will be built.
// This is optional.
WorkspaceFolder string
Expand Down Expand Up @@ -383,6 +385,12 @@ func (o *Options) CLI() serpent.OptionSet {
Value: serpent.StringOf(&o.GitPassword),
Description: "The password to use for Git authentication. This is optional.",
},
{
Flag: "git-ref",
Env: WithEnvPrefix("GIT_REF"),
Value: serpent.StringOf(&o.GitRef),
Description: "The git ref to checkout for Git repositories. This is optional.",
},
{
Flag: "git-ssh-private-key-path",
Env: WithEnvPrefix("GIT_SSH_PRIVATE_KEY_PATH"),
Expand Down