Skip to content

Commit 71555b8

Browse files
authored
feat: add git clone with thinpack option to support self hosted azure devops (#446)
1 parent 6f12850 commit 71555b8

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

docs/env-variables.md

Lines changed: 1 addition & 0 deletions
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` | `true` | Git clone with thin pack compatibility enabled, ensuring that even when thin pack compatibility is activated,it will not be turned on for the domain dev.zaure.com. |
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

Lines changed: 14 additions & 2 deletions
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,13 @@ 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+
58+
thinPack := true
59+
60+
if !opts.ThinPack {
61+
thinPack = false
62+
logf("ThinPack options is false, Marking thin-pack as unsupported")
63+
} else if parsed.Hostname() == "dev.azure.com" {
5764
// Azure DevOps requires capabilities multi_ack / multi_ack_detailed,
5865
// which are not fully implemented and by default are included in
5966
// transport.UnsupportedCapabilities.
@@ -71,10 +78,14 @@ func CloneRepo(ctx context.Context, logf func(string, ...any), opts CloneRepoOpt
7178
//
7279
// This is knowingly not safe to call in parallel, but it seemed
7380
// like the least-janky place to add a super janky hack.
81+
thinPack = false
82+
logf("Workaround for Azure DevOps: marking thin-pack as unsupported")
83+
}
84+
85+
if !thinPack {
7486
transport.UnsupportedCapabilities = []capability.Capability{
7587
capability.ThinPack,
7688
}
77-
logf("Workaround for Azure DevOps: marking thin-pack as unsupported")
7889
}
7990

8091
err = opts.Storage.MkdirAll(opts.Path, 0o755)
@@ -347,6 +358,7 @@ func CloneOptionsFromOptions(logf func(string, ...any), options options.Options)
347358
Storage: options.Filesystem,
348359
Insecure: options.Insecure,
349360
SingleBranch: options.GitCloneSingleBranch,
361+
ThinPack: options.GitCloneThinPack,
350362
Depth: int(options.GitCloneDepth),
351363
CABundle: caBundle,
352364
}

options/options.go

Lines changed: 11 additions & 0 deletions
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,15 @@ 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+
Default: "true",
385+
Description: "Git clone with thin pack compatibility enabled, " +
386+
"ensuring that even when thin pack compatibility is activated," +
387+
"it will not be turned on for the domain dev.zaure.com.",
388+
},
378389
{
379390
Flag: "git-username",
380391
Env: WithEnvPrefix("GIT_USERNAME"),

options/options_test.go

Lines changed: 8 additions & 0 deletions
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.True(t, o.GitCloneThinPack)
6674
})
6775
})
6876
}

options/testdata/options.golden

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ 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 (default: true)
103+
Git clone with thin pack compatibility enabled, ensuring that even
104+
when thin pack compatibility is activated,it will not be turned on for
105+
the domain dev.zaure.com.
106+
102107
--git-http-proxy-url string, $ENVBUILDER_GIT_HTTP_PROXY_URL
103108
The URL for the HTTP proxy. This is optional.
104109

0 commit comments

Comments
 (0)