Skip to content

Commit

Permalink
autosync changes
Browse files Browse the repository at this point in the history
  • Loading branch information
csweichel committed Nov 2, 2023
1 parent 720b3ce commit 7277f95
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
28 changes: 28 additions & 0 deletions components/local-app/cmd/workspace-up.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
4 changes: 4 additions & 0 deletions components/local-app/pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 7277f95

Please sign in to comment.