Skip to content

Commit 2a22162

Browse files
committed
feat: add git clone with thinkpack option to support self hosted azure devops
1 parent d045c1c commit 2a22162

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

docs/env-variables.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
| `--git-url` | `ENVBUILDER_GIT_URL` | | The URL of a Git repository containing a Devcontainer or Docker image to clone. This is optional. |
2828
| `--git-clone-depth` | `ENVBUILDER_GIT_CLONE_DEPTH` | | The depth to use when cloning the Git repository. |
2929
| `--git-clone-single-branch` | `ENVBUILDER_GIT_CLONE_SINGLE_BRANCH` | | Clone only a single branch of the Git repository. |
30+
| `--git-clone-thinpack` | `ENVBUILDER_GIT_CLONE_THINPACK` | | Clone with thin pack compabilities. |
3031
| `--git-username` | `ENVBUILDER_GIT_USERNAME` | | The username to use for Git authentication. This is optional. |
3132
| `--git-password` | `ENVBUILDER_GIT_PASSWORD` | | The password to use for Git authentication. This is optional. |
3233
| `--git-ssh-private-key-path` | `ENVBUILDER_GIT_SSH_PRIVATE_KEY_PATH` | | Path to an SSH private key to be used for Git authentication. If this is set, then GIT_SSH_PRIVATE_KEY_BASE64 cannot be set. |

git/git.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type CloneRepoOptions struct {
3737
Progress sideband.Progress
3838
Insecure bool
3939
SingleBranch bool
40+
ThinPack bool
4041
Depth int
4142
CABundle []byte
4243
ProxyOptions transport.ProxyOptions
@@ -53,7 +54,7 @@ func CloneRepo(ctx context.Context, logf func(string, ...any), opts CloneRepoOpt
5354
return false, fmt.Errorf("parse url %q: %w", opts.RepoURL, err)
5455
}
5556
logf("Parsed Git URL as %q", parsed.Redacted())
56-
if parsed.Hostname() == "dev.azure.com" {
57+
if parsed.Hostname() == "dev.azure.com" || opts.ThinPack {
5758
// Azure DevOps requires capabilities multi_ack / multi_ack_detailed,
5859
// which are not fully implemented and by default are included in
5960
// transport.UnsupportedCapabilities.
@@ -347,6 +348,7 @@ func CloneOptionsFromOptions(logf func(string, ...any), options options.Options)
347348
Storage: options.Filesystem,
348349
Insecure: options.Insecure,
349350
SingleBranch: options.GitCloneSingleBranch,
351+
ThinPack: options.GitCloneThinPack,
350352
Depth: int(options.GitCloneDepth),
351353
CABundle: caBundle,
352354
}

options/options.go

+8
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ type Options struct {
106106
GitCloneDepth int64
107107
// GitCloneSingleBranch clone only a single branch of the Git repository.
108108
GitCloneSingleBranch bool
109+
// GitCloneThinPack clone with thin pack compabilities. This is optional.
110+
GitCloneThinPack bool
109111
// GitUsername is the username to use for Git authentication. This is
110112
// optional.
111113
GitUsername string
@@ -375,6 +377,12 @@ func (o *Options) CLI() serpent.OptionSet {
375377
Value: serpent.BoolOf(&o.GitCloneSingleBranch),
376378
Description: "Clone only a single branch of the Git repository.",
377379
},
380+
{
381+
Flag: "git-clone-thinpack",
382+
Env: WithEnvPrefix("GIT_CLONE_THINPACK"),
383+
Value: serpent.BoolOf(&o.GitCloneThinPack),
384+
Description: "Clone with thin pack compabilities.",
385+
},
378386
{
379387
Flag: "git-username",
380388
Env: WithEnvPrefix("GIT_USERNAME"),

options/options_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,39 @@ func TestEnvOptionParsing(t *testing.T) {
3838
t.Run("lowercase", func(t *testing.T) {
3939
t.Setenv(options.WithEnvPrefix("SKIP_REBUILD"), "true")
4040
t.Setenv(options.WithEnvPrefix("GIT_CLONE_SINGLE_BRANCH"), "false")
41+
t.Setenv(options.WithEnvPrefix("GIT_CLONE_THINPACK"), "false")
4142
o := runCLI()
4243
require.True(t, o.SkipRebuild)
4344
require.False(t, o.GitCloneSingleBranch)
45+
require.False(t, o.GitCloneThinPack)
4446
})
4547

4648
t.Run("uppercase", func(t *testing.T) {
4749
t.Setenv(options.WithEnvPrefix("SKIP_REBUILD"), "TRUE")
4850
t.Setenv(options.WithEnvPrefix("GIT_CLONE_SINGLE_BRANCH"), "FALSE")
51+
t.Setenv(options.WithEnvPrefix("GIT_CLONE_THINPACK"), "FALSE")
4952
o := runCLI()
5053
require.True(t, o.SkipRebuild)
5154
require.False(t, o.GitCloneSingleBranch)
55+
require.False(t, o.GitCloneThinPack)
5256
})
5357

5458
t.Run("numeric", func(t *testing.T) {
5559
t.Setenv(options.WithEnvPrefix("SKIP_REBUILD"), "1")
5660
t.Setenv(options.WithEnvPrefix("GIT_CLONE_SINGLE_BRANCH"), "0")
61+
t.Setenv(options.WithEnvPrefix("GIT_CLONE_THINPACK"), "0")
5762
o := runCLI()
5863
require.True(t, o.SkipRebuild)
5964
require.False(t, o.GitCloneSingleBranch)
65+
require.False(t, o.GitCloneThinPack)
6066
})
6167

6268
t.Run("empty", func(t *testing.T) {
6369
t.Setenv(options.WithEnvPrefix("GIT_CLONE_SINGLE_BRANCH"), "")
70+
t.Setenv(options.WithEnvPrefix("GIT_CLONE_THINPACK"), "")
6471
o := runCLI()
6572
require.False(t, o.GitCloneSingleBranch)
73+
require.False(t, o.GitCloneThinPack)
6674
})
6775
})
6876
}

options/testdata/options.golden

+3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ OPTIONS:
9999
--git-clone-single-branch bool, $ENVBUILDER_GIT_CLONE_SINGLE_BRANCH
100100
Clone only a single branch of the Git repository.
101101

102+
--git-clone-thinpack bool, $ENVBUILDER_GIT_CLONE_THINPACK
103+
Clone with thin pack compabilities.
104+
102105
--git-http-proxy-url string, $ENVBUILDER_GIT_HTTP_PROXY_URL
103106
The URL for the HTTP proxy. This is optional.
104107

0 commit comments

Comments
 (0)