Skip to content
Merged
Changes from 3 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
43 changes: 25 additions & 18 deletions components/supervisor/pkg/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ func Run(options ...RunOption) {
return
}

var (
ideReady = newIDEReadyState(&cfg.IDE)
desktopIdeReady *ideReadyState = nil

cstate = NewInMemoryContentState(cfg.RepoRoot)
gitpodService serverapi.APIInterface

notificationService = NewNotificationService()
)

endpoint, host, err := cfg.GitpodAPIEndpoint()
if err != nil {
log.WithError(err).Fatal("cannot find Gitpod API endpoint")
Expand All @@ -211,6 +221,14 @@ func Run(options ...RunOption) {
symlinkBinaries(cfg)

configureGit(cfg)
go func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filiptronicek What about moving the go fun()... into `configureGit()´? Feels that would match the pattern we have going here, and reduces the noise on the outside. 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, will move it to reduce the LOC we have in the main supervisor func. The reason I put it here at first is to not have to pass the cstate around.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0712aea (#20548)

<-cstate.ContentReady()
if cfg.CommitAnnotationEnabled && !cfg.isHeadless() {
if err := setupGitMessageHook(filepath.Join(cfg.RepoRoot, ".git", "hooks")); err != nil {
log.WithError(err).Error("cannot setup git message hook")
}
}
}()

telemetry := analytics.NewFromEnvironment()
defer telemetry.Close()
Expand Down Expand Up @@ -260,16 +278,6 @@ func Run(options ...RunOption) {
internalPorts = append(internalPorts, debugProxyPort)
}

var (
ideReady = newIDEReadyState(&cfg.IDE)
desktopIdeReady *ideReadyState = nil

cstate = NewInMemoryContentState(cfg.RepoRoot)
gitpodService serverapi.APIInterface

notificationService = NewNotificationService()
)

if !opts.RunGP {
gitpodService = serverapi.NewServerApiService(ctx, &serverapi.ServiceConfig{
Host: host,
Expand Down Expand Up @@ -818,13 +826,6 @@ func configureGit(cfg *Config) {
settings = append(settings, []string{"user.email", cfg.GitEmail})
}

if cfg.CommitAnnotationEnabled {
err := setupGitMessageHook(filepath.Join(cfg.RepoRoot, ".git", "hooks"))
if err != nil {
log.WithError(err).Error("cannot setup git message hook")
}
}

for _, s := range settings {
cmd := exec.Command("git", append([]string{"config", "--global"}, s...)...)
cmd = runAsGitpodUser(cmd)
Expand All @@ -845,15 +846,21 @@ func setupGitMessageHook(path string) error {
if err := os.MkdirAll(path, 0755); err != nil {
return err
}
if err := os.Chown(path, gitpodUID, gitpodGID); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, wonder whether there is a nicer way to do that... but can't imagine one, besides resorting to a shell and exec.Command etc.
So I guess what we have here is the best solution. 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like Claude agrees with me, but it offered to move the chown block so that the two chowns are just besides each other. Made that change in c0de48f (#20548), but if we ever introduce more hooks, we could recursively walk the tree to chown instead of calling os.Chown multiple times explicitly.

return err
}

fn := filepath.Join(path, "prepare-commit-msg")
// do not override existing hooks. Relevant for workspaces based off of prebuilds, which might already have a hook.
// do not override existing hooks
if _, err := os.Stat(fn); err == nil {
return nil
}
if err := os.WriteFile(fn, []byte(hookContent), 0755); err != nil {
return err
}
if err := os.Chown(fn, gitpodUID, gitpodGID); err != nil {
return err
}

return nil
}
Expand Down
Loading