File tree 2 files changed +56
-0
lines changed
2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ Here you can find a list of annotated _go-git_ examples:
20
20
- [ remotes] ( remotes/main.go ) - Working with remotes: adding, removing, etc
21
21
- [ progress] ( progress/main.go ) - Printing the progress information from the sideband
22
22
- [ revision] ( revision/main.go ) - Solve a revision into a commit
23
+ - [ submodule] ( submodule/main.go ) - Submodule update remote
23
24
24
25
### Advanced
25
26
- [ custom_http] ( custom_http/main.go ) - Replacing the HTTP client using a custom one
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "os"
5
+
6
+ "github.com/go-git/go-git/v5"
7
+ . "github.com/go-git/go-git/v5/_examples"
8
+ )
9
+
10
+ // Basic example of how to clone a repository including a submodule and
11
+ // updating submodule ref
12
+ func 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
+ }
You can’t perform that action at this time.
0 commit comments