Skip to content

Commit 02b4952

Browse files
mustard-mhfiliptronicekgeropl
authored
Add full clone setting for prebuilds (#20177)
* proto update Co-authored-by: Filip Troníček <[email protected]> Co-authored-by: Gero Posmyk-Leinemann <[email protected]> * dashboard + server --------- Co-authored-by: Filip Troníček <[email protected]> Co-authored-by: Gero Posmyk-Leinemann <[email protected]>
1 parent c489f17 commit 02b4952

File tree

23 files changed

+1787
-590
lines changed

23 files changed

+1787
-590
lines changed

components/content-service-api/go/initializer.pb.go

Lines changed: 92 additions & 81 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/content-service-api/initializer.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ message GitInitializer {
6161

6262
// config specifies the Git configuration for this workspace
6363
GitConfig config = 6;
64+
65+
// full_clone determines if the entire repository should be cloned, instead of with `--depth=1`
66+
bool full_clone = 7;
6467
}
6568

6669
// CloneTargetMode is the target state in which we want to leave a GitWorkspace

components/content-service-api/typescript/src/initializer_pb.d.ts

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/content-service-api/typescript/src/initializer_pb.js

Lines changed: 31 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/content-service/pkg/git/git.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"os/exec"
1414
"path/filepath"
1515
"strings"
16+
"time"
1617

1718
"github.com/opentracing/opentracing-go"
1819
"golang.org/x/xerrors"
@@ -95,6 +96,9 @@ type Client struct {
9596

9697
// if true will run git command as gitpod user (should be executed as root that has access to sudo in this case)
9798
RunAsGitpodUser bool
99+
100+
// FullClone indicates whether we should do a full checkout or a shallow clone
101+
FullClone bool
98102
}
99103

100104
// Status describes the status of a Git repo/working copy akin to "git status"
@@ -338,8 +342,18 @@ func (c *Client) Clone(ctx context.Context) (err error) {
338342
log.WithError(err).Error("cannot create clone location")
339343
}
340344

345+
now := time.Now()
346+
347+
defer func() {
348+
log.WithField("duration", time.Since(now).String()).WithField("FullClone", c.FullClone).Info("clone repository took")
349+
}()
350+
341351
args := []string{"--depth=1", "--shallow-submodules", c.RemoteURI}
342352

353+
if c.FullClone {
354+
args = []string{c.RemoteURI}
355+
}
356+
343357
for key, value := range c.Config {
344358
args = append(args, "--config")
345359
args = append(args, strings.TrimSpace(key)+"="+strings.TrimSpace(value))

components/content-service/pkg/initializer/git.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"os"
1212
"os/exec"
13+
"strconv"
1314
"strings"
1415
"time"
1516

@@ -199,6 +200,20 @@ func (ws *GitInitializer) Run(ctx context.Context, mappings []archive.IDMapping)
199200
return
200201
}
201202

203+
func (ws *GitInitializer) isShallowRepository(ctx context.Context) bool {
204+
out, err := ws.GitWithOutput(ctx, nil, "rev-parse", "--is-shallow-repository")
205+
if err != nil {
206+
log.WithError(err).Error("unexpected error checking if git repository is shallow")
207+
return true
208+
}
209+
isShallow, err := strconv.ParseBool(strings.TrimSpace(string(out)))
210+
if err != nil {
211+
log.WithError(err).WithField("input", string(out)).Error("unexpected error parsing bool")
212+
return true
213+
}
214+
return isShallow
215+
}
216+
202217
// realizeCloneTarget ensures the clone target is checked out
203218
func (ws *GitInitializer) realizeCloneTarget(ctx context.Context) (err error) {
204219
//nolint:ineffassign
@@ -235,8 +250,13 @@ func (ws *GitInitializer) realizeCloneTarget(ctx context.Context) (err error) {
235250
//
236251
// We don't recurse submodules because callers realizeCloneTarget() are expected to update submodules explicitly,
237252
// and deal with any error appropriately (i.e. emit a warning rather than fail).
238-
if err := ws.Git(ctx, "fetch", "--depth=1", "origin", "--recurse-submodules=no", ws.CloneTarget); err != nil {
239-
log.WithError(err).WithField("remoteURI", ws.RemoteURI).WithField("branch", ws.CloneTarget).Error("Cannot fetch remote branch")
253+
fetchArgs := []string{"--depth=1", "origin", "--recurse-submodules=no", ws.CloneTarget}
254+
isShallow := ws.isShallowRepository(ctx)
255+
if !isShallow {
256+
fetchArgs = []string{"origin", "--recurse-submodules=no", ws.CloneTarget}
257+
}
258+
if err := ws.Git(ctx, "fetch", fetchArgs...); err != nil {
259+
log.WithError(err).WithField("isShallow", isShallow).WithField("remoteURI", ws.RemoteURI).WithField("branch", ws.CloneTarget).Error("Cannot fetch remote branch")
240260
return err
241261
}
242262

components/content-service/pkg/initializer/initializer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ func newGitInitializer(ctx context.Context, loc string, req *csapi.GitInitialize
304304
AuthMethod: authMethod,
305305
AuthProvider: authProvider,
306306
RunAsGitpodUser: forceGitpodUser,
307+
FullClone: req.FullClone,
307308
},
308309
TargetMode: targetMode,
309310
CloneTarget: req.CloneTaget,

components/dashboard/src/data/featureflag-query.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const featureFlags = {
2424
dataops: false,
2525
showBrowserExtensionPromotion: false,
2626
enable_experimental_jbtb: false,
27+
enabled_configuration_prebuild_full_clone: false,
2728
};
2829

2930
type FeatureFlags = typeof featureFlags;

components/dashboard/src/repositories/detail/prebuilds/PrebuildSettingsForm.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import { useUserLoader } from "../../../hooks/use-user-loader";
2626
import { useUpdateCurrentUserMutation } from "../../../data/current-user/update-mutation";
2727
import { trackEvent } from "../../../Analytics";
2828
import dayjs from "dayjs";
29+
import { SwitchInputField } from "@podkit/switch/Switch";
30+
import { useFeatureFlag } from "../../../data/featureflag-query";
2931

3032
const DEFAULT_PREBUILD_COMMIT_INTERVAL = 20;
3133

@@ -40,6 +42,7 @@ export const PrebuildSettingsForm: FC<Props> = ({ configuration }) => {
4042

4143
const { user } = useUserLoader();
4244
const { mutate: updateUser } = useUpdateCurrentUserMutation();
45+
const isEnabledPrebuildFullClone = useFeatureFlag("enabled_configuration_prebuild_full_clone");
4346

4447
const updateConfiguration = useConfigurationMutation();
4548

@@ -55,6 +58,9 @@ export const PrebuildSettingsForm: FC<Props> = ({ configuration }) => {
5558
const [workspaceClass, setWorkspaceClass] = useState<string>(
5659
configuration.prebuildSettings?.workspaceClass || DEFAULT_WS_CLASS,
5760
);
61+
const [fullClone, setFullClone] = useState<boolean>(
62+
configuration.prebuildSettings?.cloneSettings?.fullClone ?? false,
63+
);
5864

5965
const [isTriggerNotificationOpen, setIsTriggerNotificationOpen] = useState(true);
6066

@@ -72,6 +78,9 @@ export const PrebuildSettingsForm: FC<Props> = ({ configuration }) => {
7278
branchStrategy,
7379
branchMatchingPattern,
7480
workspaceClass,
81+
cloneSettings: {
82+
fullClone,
83+
},
7584
},
7685
};
7786

@@ -90,6 +99,7 @@ export const PrebuildSettingsForm: FC<Props> = ({ configuration }) => {
9099
toast,
91100
updateConfiguration,
92101
workspaceClass,
102+
fullClone,
93103
],
94104
);
95105

@@ -200,6 +210,20 @@ export const PrebuildSettingsForm: FC<Props> = ({ configuration }) => {
200210
/>
201211
)}
202212

213+
{isEnabledPrebuildFullClone && (
214+
<InputField
215+
label="Clone repositories in full"
216+
hint="Make prebuilds fully clone the repository, maintaining the entire git history for use in prebuilds and workspaces."
217+
>
218+
<SwitchInputField
219+
id="prebuild-full-clone-enabled"
220+
checked={fullClone}
221+
onCheckedChange={setFullClone}
222+
label=""
223+
/>
224+
</InputField>
225+
)}
226+
203227
<Heading3 className="mt-8">Machine type</Heading3>
204228
<Subheading>Choose the workspace machine type for your prebuilds.</Subheading>
205229

components/gitpod-protocol/src/teams-projects-protocol.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export interface ProjectSettings {
3232
export namespace PrebuildSettings {
3333
export type BranchStrategy = "default-branch" | "all-branches" | "matched-branches";
3434
export type TriggerStrategy = "activity-based" | "webhook-based";
35+
export interface CloneSettings {
36+
fullClone?: boolean;
37+
}
3538
}
3639

3740
export interface PrebuildSettings {
@@ -61,6 +64,8 @@ export interface PrebuildSettings {
6164
* The activation strategy for prebuilds. Defaults to "webhook-based"
6265
*/
6366
triggerStrategy?: PrebuildSettings.TriggerStrategy;
67+
68+
cloneSettings?: PrebuildSettings.CloneSettings;
6469
}
6570

6671
export interface Project {

0 commit comments

Comments
 (0)