Skip to content
Merged
Changes from 4 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
48 changes: 28 additions & 20 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 @@ -210,7 +220,7 @@ func Run(options ...RunOption) {
}
symlinkBinaries(cfg)

configureGit(cfg)
configureGit(cfg, cstate.ContentReady())

telemetry := analytics.NewFromEnvironment()
defer telemetry.Close()
Expand Down Expand Up @@ -260,16 +270,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 @@ -804,7 +804,7 @@ func symlinkBinaries(cfg *Config) {
}
}

func configureGit(cfg *Config) {
func configureGit(cfg *Config, contentReady <-chan struct{}) {
settings := [][]string{
{"push.default", "simple"},
{"alias.lg", "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"},
Expand All @@ -818,13 +818,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 @@ -835,6 +828,15 @@ func configureGit(cfg *Config) {
log.WithError(err).WithField("args", s).Warn("git config error")
}
}

go func() {
<-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")
}
}
}()
}

const hookContent = `#!/bin/sh
Expand All @@ -845,15 +847,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