MCPcopy
hub / github.com/go-git/go-git / main

Function main

_examples/submodule/main.go:12–55  ·  view source on GitHub ↗

Basic example of how to clone a repository including a submodule and updating submodule ref

()

Source from the content-addressed store, hash-verified

10// Basic example of how to clone a repository including a submodule and
11// updating submodule ref
12func main() {
13 CheckArgs("<url>", "<directory>", "<submodule>")
14 url := os.Args[1]
15 directory := os.Args[2]
16 submodule := os.Args[3]
17
18 // Clone the given repository to the given directory
19 Info("git clone %s %s --recursive", url, directory)
20
21 r, err := git.PlainClone(directory, false, &git.CloneOptions{
22 URL: url,
23 RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
24 })
25
26 CheckIfError(err)
27
28 w, err := r.Worktree()
29 if err != nil {
30 CheckIfError(err)
31 }
32
33 sub, err := w.Submodule(submodule)
34 if err != nil {
35 CheckIfError(err)
36 }
37
38 sr, err := sub.Repository()
39 if err != nil {
40 CheckIfError(err)
41 }
42
43 sw, err := sr.Worktree()
44 if err != nil {
45 CheckIfError(err)
46 }
47
48 Info("git submodule update --remote")
49 err = sw.Pull(&git.PullOptions{
50 RemoteName: "origin",
51 })
52 if err != nil {
53 CheckIfError(err)
54 }
55}

Callers

nothing calls this directly

Calls 7

CheckArgsFunction · 0.85
InfoFunction · 0.85
CheckIfErrorFunction · 0.85
WorktreeMethod · 0.80
SubmoduleMethod · 0.80
RepositoryMethod · 0.80
PullMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…