Pull This can be rewritten to be more readable and less repetitive. Possibly something like: puller := getPullerForURL(url) return puller.Pull()
(ctx context.Context)
| 39 | // puller := getPullerForURL(url) |
| 40 | // return puller.Pull() |
| 41 | func (p *pullbox) Pull(ctx context.Context) error { |
| 42 | defer trace.StartRegion(ctx, "Pull").End() |
| 43 | var err error |
| 44 | |
| 45 | notEmpty, err := profileIsNotEmpty(p.ProjectDir()) |
| 46 | if err != nil { |
| 47 | return err |
| 48 | } else if notEmpty && !p.Overwrite { |
| 49 | return fs.ErrExist |
| 50 | } |
| 51 | |
| 52 | if p.URL != "" { |
| 53 | ux.Finfof(os.Stderr, "Pulling global config from %s\n", p.URL) |
| 54 | } else { |
| 55 | ux.Finfof(os.Stderr, "Pulling global config\n") |
| 56 | } |
| 57 | |
| 58 | var tmpDir string |
| 59 | |
| 60 | if p.URL == "" { |
| 61 | if p.Credentials.IDToken == "" { |
| 62 | return usererr.New("Not logged in") |
| 63 | } |
| 64 | profile := "default" // TODO: make this editable |
| 65 | if tmpDir, err = s3.PullToTmp(ctx, &p.Credentials, profile); err != nil { |
| 66 | return err |
| 67 | } |
| 68 | return p.copyToProfile(tmpDir) |
| 69 | } |
| 70 | |
| 71 | if git.IsRepoURL(p.URL) { |
| 72 | if tmpDir, err = git.CloneToTmp(p.URL); err != nil { |
| 73 | return err |
| 74 | } |
| 75 | // Remove the .git directory, we don't want to keep state |
| 76 | if err := os.RemoveAll(filepath.Join(tmpDir, ".git")); err != nil { |
| 77 | return errors.WithStack(err) |
| 78 | } |
| 79 | return p.copyToProfile(tmpDir) |
| 80 | } |
| 81 | |
| 82 | if p.IsTextDevboxConfig() { |
| 83 | return p.pullTextDevboxConfig(ctx) |
| 84 | } |
| 85 | |
| 86 | if isArchive, err := urlIsArchive(p.URL); err != nil { |
| 87 | return err |
| 88 | } else if isArchive { |
| 89 | data, err := download(p.URL) |
| 90 | if err != nil { |
| 91 | return err |
| 92 | } |
| 93 | |
| 94 | if tmpDir, err = tar.Extract(data); err != nil { |
| 95 | return err |
| 96 | } |
| 97 | |
| 98 | return p.copyToProfile(tmpDir) |
nothing calls this directly
no test coverage detected