MCPcopy Index your code
hub / github.com/devspace-sh/devspace / Update

Method Update

pkg/util/git/go_git.go:27–87  ·  view source on GitHub ↗

Update pulls the repository or clones it into the local path

(merge bool)

Source from the content-addressed store, hash-verified

25
26// Update pulls the repository or clones it into the local path
27func (gr *GoGitRepository) Update(merge bool) error {
28 // Check if repo already exists
29 _, err := os.Stat(gr.LocalPath + "/.git")
30 if err != nil {
31 // Create local path
32 err := os.MkdirAll(gr.LocalPath, 0755)
33 if err != nil {
34 return err
35 }
36
37 // Check
38 // Clone into folder
39 _, err = git.PlainClone(gr.LocalPath, false, &git.CloneOptions{
40 URL: gr.RemoteURL,
41 })
42 if err != nil {
43 return err
44 }
45
46 return nil
47 }
48
49 // Open existing repo
50 repo, err := git.PlainOpen(gr.LocalPath)
51 if err != nil {
52 return err
53 }
54
55 // Pull or fetch?
56 if merge {
57 repoWorktree, err := repo.Worktree()
58 if err != nil {
59 return err
60 }
61
62 // Make sure main is checked out
63 err = repoWorktree.Checkout(&git.CheckoutOptions{
64 Branch: plumbing.ReferenceName("refs/heads/main"),
65 Create: false,
66 })
67 if err != nil {
68 return err
69 }
70
71 err = repoWorktree.Pull(&git.PullOptions{
72 RemoteName: "origin",
73 })
74 if err != git.NoErrAlreadyUpToDate && err != nil {
75 return err
76 }
77 } else {
78 err = repo.Fetch(&git.FetchOptions{
79 RemoteName: "origin",
80 })
81 if err != git.NoErrAlreadyUpToDate && err != nil {
82 return err
83 }
84 }

Callers 1

TestGoGitFunction · 0.95

Calls 2

CheckoutMethod · 0.80
PullMethod · 0.80

Tested by 1

TestGoGitFunction · 0.76