@@ -17,6 +17,7 @@ import (
17
17
"io/ioutil"
18
18
"net"
19
19
"net/http"
20
+ "net/url"
20
21
"os"
21
22
"os/exec"
22
23
"os/signal"
@@ -46,6 +47,7 @@ import (
46
47
"github.com/gitpod-io/gitpod/common-go/process"
47
48
csapi "github.com/gitpod-io/gitpod/content-service/api"
48
49
"github.com/gitpod-io/gitpod/content-service/pkg/executor"
50
+ "github.com/gitpod-io/gitpod/content-service/pkg/git"
49
51
"github.com/gitpod-io/gitpod/content-service/pkg/initializer"
50
52
gitpod "github.com/gitpod-io/gitpod/gitpod-protocol"
51
53
"github.com/gitpod-io/gitpod/supervisor/api"
@@ -283,7 +285,7 @@ func Run(options ...RunOption) {
283
285
284
286
// We need to checkout dotfiles first, because they may be changing the path which affects the IDE.
285
287
// TODO(cw): provide better feedback if the IDE start fails because of the dotfiles (provide any feedback at all).
286
- installDotfiles (ctx , termMuxSrv , cfg )
288
+ installDotfiles (ctx , cfg , tokenService )
287
289
}
288
290
289
291
var ideWG sync.WaitGroup
@@ -370,7 +372,7 @@ func Run(options ...RunOption) {
370
372
wg .Wait ()
371
373
}
372
374
373
- func installDotfiles (ctx context.Context , term * terminal. MuxTerminalService , cfg * Config ) {
375
+ func installDotfiles (ctx context.Context , cfg * Config , tokenService * InMemoryTokenService ) {
374
376
repo := cfg .DotfileRepo
375
377
if repo == "" {
376
378
return
@@ -414,12 +416,36 @@ func installDotfiles(ctx context.Context, term *terminal.MuxTerminalService, cfg
414
416
415
417
done := make (chan error , 1 )
416
418
go func () {
417
- done <- prep (cfg , out , "git" , "clone" , "--depth=1" , repo , "/home/gitpod/.dotfiles" ).Run ()
419
+ repoUrl , err := url .Parse (repo )
420
+ if err != nil {
421
+ done <- err
422
+ close (done )
423
+ return
424
+ }
425
+ authProvider := func () (username string , password string , err error ) {
426
+ resp , err := tokenService .GetToken (ctx , & api.GetTokenRequest {
427
+ Host : repoUrl .Host ,
428
+ Kind : KindGit ,
429
+ })
430
+ if err != nil {
431
+ return
432
+ }
433
+ username = resp .User
434
+ password = resp .Token
435
+ return
436
+ }
437
+ client := & git.Client {
438
+ AuthProvider : authProvider ,
439
+ AuthMethod : git .BasicAuth ,
440
+ Location : "/home/gitpod/.dotfiles" ,
441
+ RemoteURI : repo ,
442
+ }
443
+ done <- client .Clone (ctx )
418
444
close (done )
419
445
}()
420
446
select {
421
447
case err := <- done :
422
- if err != nil {
448
+ if err != nil && ! process . IsNotChildProcess ( err ) {
423
449
return err
424
450
}
425
451
case <- time .After (120 * time .Second ):
@@ -469,7 +495,9 @@ func installDotfiles(ctx context.Context, term *terminal.MuxTerminalService, cfg
469
495
470
496
select {
471
497
case err = <- done :
472
- return err
498
+ if err != nil && ! process .IsNotChildProcess (err ) {
499
+ return err
500
+ }
473
501
case <- time .After (120 * time .Second ):
474
502
cmd .Process .Kill ()
475
503
return xerrors .Errorf ("installation process %s tool longer than 120 seconds" , fn )
0 commit comments