@@ -189,6 +189,16 @@ func Run(options ...RunOption) {
189
189
return
190
190
}
191
191
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
+
192
202
endpoint , host , err := cfg .GitpodAPIEndpoint ()
193
203
if err != nil {
194
204
log .WithError (err ).Fatal ("cannot find Gitpod API endpoint" )
@@ -210,7 +220,7 @@ func Run(options ...RunOption) {
210
220
}
211
221
symlinkBinaries (cfg )
212
222
213
- configureGit (cfg )
223
+ configureGit (cfg , cstate . ContentReady () )
214
224
215
225
telemetry := analytics .NewFromEnvironment ()
216
226
defer telemetry .Close ()
@@ -260,16 +270,6 @@ func Run(options ...RunOption) {
260
270
internalPorts = append (internalPorts , debugProxyPort )
261
271
}
262
272
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
-
273
273
if ! opts .RunGP {
274
274
gitpodService = serverapi .NewServerApiService (ctx , & serverapi.ServiceConfig {
275
275
Host : host ,
@@ -804,7 +804,7 @@ func symlinkBinaries(cfg *Config) {
804
804
}
805
805
}
806
806
807
- func configureGit (cfg * Config ) {
807
+ func configureGit (cfg * Config , contentReady <- chan struct {} ) {
808
808
settings := [][]string {
809
809
{"push.default" , "simple" },
810
810
{"alias.lg" , "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" },
@@ -818,13 +818,6 @@ func configureGit(cfg *Config) {
818
818
settings = append (settings , []string {"user.email" , cfg .GitEmail })
819
819
}
820
820
821
- if cfg .CommitAnnotationEnabled {
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
-
828
821
for _ , s := range settings {
829
822
cmd := exec .Command ("git" , append ([]string {"config" , "--global" }, s ... )... )
830
823
cmd = runAsGitpodUser (cmd )
@@ -835,6 +828,15 @@ func configureGit(cfg *Config) {
835
828
log .WithError (err ).WithField ("args" , s ).Warn ("git config error" )
836
829
}
837
830
}
831
+
832
+ go func () {
833
+ <- contentReady
834
+ if cfg .CommitAnnotationEnabled && ! cfg .isHeadless () {
835
+ if err := setupGitMessageHook (filepath .Join (cfg .RepoRoot , ".git" , "hooks" )); err != nil {
836
+ log .WithError (err ).Error ("cannot setup git message hook" )
837
+ }
838
+ }
839
+ }()
838
840
}
839
841
840
842
const hookContent = `#!/bin/sh
@@ -847,14 +849,22 @@ func setupGitMessageHook(path string) error {
847
849
}
848
850
849
851
fn := filepath .Join (path , "prepare-commit-msg" )
850
- // do not override existing hooks. Relevant for workspaces based off of prebuilds, which might already have a hook.
852
+ // do not override existing hooks
851
853
if _ , err := os .Stat (fn ); err == nil {
852
854
return nil
853
855
}
854
856
if err := os .WriteFile (fn , []byte (hookContent ), 0755 ); err != nil {
855
857
return err
856
858
}
857
859
860
+ // Change ownership of both path and file to the gitpod user
861
+ if err := os .Chown (path , gitpodUID , gitpodGID ); err != nil {
862
+ return err
863
+ }
864
+ if err := os .Chown (fn , gitpodUID , gitpodGID ); err != nil {
865
+ return err
866
+ }
867
+
858
868
return nil
859
869
}
860
870
0 commit comments