From 7277f95ce4653a151a51933d45e547b0be7d20d5 Mon Sep 17 00:00:00 2001 From: "Christian Weichel (Chris)" Date: Thu, 2 Nov 2023 21:23:11 +0000 Subject: [PATCH] autosync changes --- components/local-app/cmd/workspace-up.go | 28 +++++++++++++++++++++++ components/local-app/pkg/common/common.go | 4 ++++ 2 files changed, 32 insertions(+) diff --git a/components/local-app/cmd/workspace-up.go b/components/local-app/cmd/workspace-up.go index 8c7c9ab36aa1a3..3a3bd4dbb5ec6b 100644 --- a/components/local-app/cmd/workspace-up.go +++ b/components/local-app/cmd/workspace-up.go @@ -170,6 +170,34 @@ var workspaceUpCmd = &cobra.Command{ return err } + fmt.Printf("\nIf you want to track your workspace's changes, run \n\tgit branch --set-upstream-to=gitpod/%s %s\n", branch, branch) + + wt, err := repo.Worktree() + if err != nil { + return err + } + pullRemote := func() { + err := wt.Pull(&git.PullOptions{ + RemoteName: "gitpod", + SingleBranch: true, + Force: true, + ReferenceName: head.Name(), + }) + if err != nil && strings.Contains(err.Error(), "already up-to-date") { + err = nil + } + if err != nil { + slog.Warn("cannot pull remote changes", "err", err) + } + } + go func() { + for { + time.Sleep(5 * time.Second) + pullRemote() + } + }() + defer pullRemote() + if workspaceUpOpts.OpenSSH { err = common.SSHConnectToWorkspace(ctx, workspaceID, false) if err != nil && err.Error() == "exit status 255" { diff --git a/components/local-app/pkg/common/common.go b/components/local-app/pkg/common/common.go index 6d6fa6136f5ddb..c48b6de995df1d 100644 --- a/components/local-app/pkg/common/common.go +++ b/components/local-app/pkg/common/common.go @@ -33,6 +33,10 @@ func GetTokenKeychain(host string) (token string, err error) { } func GetToken() (string, error) { + if tkn := os.Getenv("GITPOD_TOKEN"); tkn != "" { + return tkn, nil + } + host := config.GetString("host") token, err := GetTokenKeychain(host)