Skip to content

Commit a9290d7

Browse files
committed
Wait for content ready with git commit hooks
1 parent 087c38e commit a9290d7

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

components/supervisor/pkg/supervisor/supervisor.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@ func Run(options ...RunOption) {
189189
return
190190
}
191191

192+
var (
193+
ideReady = newIDEReadyState(&cfg.IDE)
194+
desktopIdeReady *ideReadyState = nil
195+
196+
cstate = NewInMemoryContentState(cfg.RepoRoot)
197+
gitpodService serverapi.APIInterface
198+
199+
notificationService = NewNotificationService()
200+
)
201+
192202
endpoint, host, err := cfg.GitpodAPIEndpoint()
193203
if err != nil {
194204
log.WithError(err).Fatal("cannot find Gitpod API endpoint")
@@ -211,6 +221,14 @@ func Run(options ...RunOption) {
211221
symlinkBinaries(cfg)
212222

213223
configureGit(cfg)
224+
go func() {
225+
<-cstate.ContentReady()
226+
if cfg.CommitAnnotationEnabled && !cfg.isHeadless() {
227+
if err := setupGitMessageHook(filepath.Join(cfg.RepoRoot, ".git", "hooks")); err != nil {
228+
log.WithError(err).Error("cannot setup git message hook")
229+
}
230+
}
231+
}()
214232

215233
telemetry := analytics.NewFromEnvironment()
216234
defer telemetry.Close()
@@ -260,16 +278,6 @@ func Run(options ...RunOption) {
260278
internalPorts = append(internalPorts, debugProxyPort)
261279
}
262280

263-
var (
264-
ideReady = newIDEReadyState(&cfg.IDE)
265-
desktopIdeReady *ideReadyState = nil
266-
267-
cstate = NewInMemoryContentState(cfg.RepoRoot)
268-
gitpodService serverapi.APIInterface
269-
270-
notificationService = NewNotificationService()
271-
)
272-
273281
if !opts.RunGP {
274282
gitpodService = serverapi.NewServerApiService(ctx, &serverapi.ServiceConfig{
275283
Host: host,
@@ -818,13 +826,6 @@ func configureGit(cfg *Config) {
818826
settings = append(settings, []string{"user.email", cfg.GitEmail})
819827
}
820828

821-
if cfg.CommitAnnotationEnabled && !cfg.isHeadless() {
822-
err := setupGitMessageHook(filepath.Join(cfg.RepoRoot, ".git", "hooks"))
823-
if err != nil {
824-
log.WithError(err).Error("cannot setup git message hook")
825-
}
826-
}
827-
828829
for _, s := range settings {
829830
cmd := exec.Command("git", append([]string{"config", "--global"}, s...)...)
830831
cmd = runAsGitpodUser(cmd)
@@ -850,7 +851,7 @@ func setupGitMessageHook(path string) error {
850851
}
851852

852853
fn := filepath.Join(path, "prepare-commit-msg")
853-
// do not override existing hooks. Relevant for workspaces based off of prebuilds, which might already have a hook.
854+
// do not override existing hooks
854855
if _, err := os.Stat(fn); err == nil {
855856
return nil
856857
}

0 commit comments

Comments
 (0)