Skip to content

Commit 7de9705

Browse files
author
Chris Mellard
committed
allow an explicit git ref to be passed so we can checkout any ref regardless of the git url 029de3
1 parent b18cd0e commit 7de9705

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

git/git.go

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type CloneRepoOptions struct {
3434

3535
RepoURL string
3636
RepoAuth transport.AuthMethod
37+
GitRef string
3738
Progress sideband.Progress
3839
Insecure bool
3940
SingleBranch bool
@@ -84,6 +85,8 @@ func CloneRepo(ctx context.Context, logf func(string, ...any), opts CloneRepoOpt
8485
reference := parsed.Fragment
8586
if reference == "" && opts.SingleBranch {
8687
reference = "refs/heads/main"
88+
} else if reference == "" && opts.GitRef != "" {
89+
reference = opts.GitRef
8790
}
8891
parsed.RawFragment = ""
8992
parsed.Fragment = ""
@@ -343,6 +346,7 @@ func CloneOptionsFromOptions(logf func(string, ...any), options options.Options)
343346

344347
cloneOpts := CloneRepoOptions{
345348
RepoURL: options.GitURL,
349+
GitRef: options.GitRef,
346350
Path: options.WorkspaceFolder,
347351
Storage: options.Filesystem,
348352
Insecure: options.Insecure,

options/options.go

+8
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ type Options struct {
120120
GitSSHPrivateKeyBase64 string
121121
// GitHTTPProxyURL is the URL for the HTTP proxy. This is optional.
122122
GitHTTPProxyURL string
123+
// GitRef is the git ref to checkout after clone. This is optional.
124+
GitRef string
123125
// WorkspaceFolder is the path to the workspace folder that will be built.
124126
// This is optional.
125127
WorkspaceFolder string
@@ -383,6 +385,12 @@ func (o *Options) CLI() serpent.OptionSet {
383385
Value: serpent.StringOf(&o.GitPassword),
384386
Description: "The password to use for Git authentication. This is optional.",
385387
},
388+
{
389+
Flag: "git-ref",
390+
Env: WithEnvPrefix("GIT_REF"),
391+
Value: serpent.StringOf(&o.GitRef),
392+
Description: "The git ref to checkout for Git repositories. This is optional.",
393+
},
386394
{
387395
Flag: "git-ssh-private-key-path",
388396
Env: WithEnvPrefix("GIT_SSH_PRIVATE_KEY_PATH"),

0 commit comments

Comments
 (0)