MCPcopy Index your code
hub / github.com/jetify-com/devbox / Pull

Method Pull

internal/pullbox/pullbox.go:41–102  ·  view source on GitHub ↗

Pull This can be rewritten to be more readable and less repetitive. Possibly something like: puller := getPullerForURL(url) return puller.Pull()

(ctx context.Context)

Source from the content-addressed store, hash-verified

39// puller := getPullerForURL(url)
40// return puller.Pull()
41func (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)

Callers

nothing calls this directly

Calls 14

copyToProfileMethod · 0.95
IsTextDevboxConfigMethod · 0.95
pullTextDevboxConfigMethod · 0.95
FinfofFunction · 0.92
NewFunction · 0.92
PullToTmpFunction · 0.92
IsRepoURLFunction · 0.92
CloneToTmpFunction · 0.92
ExtractFunction · 0.92
profileIsNotEmptyFunction · 0.85
urlIsArchiveFunction · 0.85
downloadFunction · 0.85

Tested by

no test coverage detected