5
5
package git
6
6
7
7
import (
8
- "bufio"
9
8
"fmt"
10
- "io"
11
9
"net"
12
10
"net/url"
13
11
"path"
@@ -17,90 +15,15 @@ import (
17
15
18
16
var scpSyntax = regexp .MustCompile (`^([a-zA-Z0-9_]+@)?([a-zA-Z0-9._-]+):(.*)$` )
19
17
20
- // SubModule submodule is a reference on git repository
21
- type SubModule struct {
22
- Path string
23
- URL string
24
- Branch string
25
- }
26
-
27
- // parseSubmoduleContent this is not a complete parse for gitmodules file, it only
28
- // parses the url and path of submodules
29
- func parseSubmoduleContent (r io.Reader ) (* ObjectCache , error ) {
30
- var path , url , branch string
31
- var state int // 0: find section, 1: find path and url
32
- subModules := newObjectCache ()
33
- scanner := bufio .NewScanner (r )
34
- for scanner .Scan () {
35
- line := strings .TrimSpace (scanner .Text ())
36
-
37
- // Skip empty lines and comments
38
- if line == "" || strings .HasPrefix (line , "#" ) || strings .HasPrefix (line , ";" ) {
39
- continue
40
- }
41
-
42
- // Section header [section]
43
- if strings .HasPrefix (line , "[submodule" ) && strings .HasSuffix (line , "]" ) {
44
- if path != "" && url != "" {
45
- subModules .Set (path , & SubModule {
46
- Path : path ,
47
- URL : url ,
48
- Branch : branch ,
49
- })
50
- }
51
- state = 1
52
- path = ""
53
- url = ""
54
- branch = ""
55
- continue
56
- }
57
-
58
- if state != 1 {
59
- continue
60
- }
61
-
62
- parts := strings .SplitN (line , "=" , 2 )
63
- if len (parts ) != 2 {
64
- continue
65
- }
66
- key := strings .TrimSpace (parts [0 ])
67
- value := strings .TrimSpace (parts [1 ])
68
- switch key {
69
- case "path" :
70
- path = value
71
- case "url" :
72
- url = value
73
- case "branch" :
74
- branch = value
75
- }
76
- }
77
-
78
- if err := scanner .Err (); err != nil {
79
- return nil , fmt .Errorf ("error reading file: %w" , err )
80
- }
81
- if path != "" && url != "" {
82
- subModules .Set (path , & SubModule {
83
- Path : path ,
84
- URL : url ,
85
- Branch : branch ,
86
- })
87
- }
88
-
89
- return subModules , nil
90
- }
91
-
92
- // SubModuleFile represents a file with submodule type.
93
- type SubModuleFile struct {
94
- * Commit
95
-
18
+ // CommitSubModuleFile represents a file with submodule type.
19
+ type CommitSubModuleFile struct {
96
20
refURL string
97
21
refID string
98
22
}
99
23
100
- // NewSubModuleFile create a new submodule file
101
- func NewSubModuleFile (c * Commit , refURL , refID string ) * SubModuleFile {
102
- return & SubModuleFile {
103
- Commit : c ,
24
+ // NewCommitSubModuleFile create a new submodule file
25
+ func NewCommitSubModuleFile (refURL , refID string ) * CommitSubModuleFile {
26
+ return & CommitSubModuleFile {
104
27
refURL : refURL ,
105
28
refID : refID ,
106
29
}
@@ -177,11 +100,12 @@ func getRefURL(refURL, urlPrefix, repoFullName, sshDomain string) string {
177
100
}
178
101
179
102
// RefURL guesses and returns reference URL.
180
- func (sf * SubModuleFile ) RefURL (urlPrefix , repoFullName , sshDomain string ) string {
103
+ // FIXME: template passes AppURL as urlPrefix, it needs to figure out the correct approach (no hard-coded AppURL anymore)
104
+ func (sf * CommitSubModuleFile ) RefURL (urlPrefix , repoFullName , sshDomain string ) string {
181
105
return getRefURL (sf .refURL , urlPrefix , repoFullName , sshDomain )
182
106
}
183
107
184
108
// RefID returns reference ID.
185
- func (sf * SubModuleFile ) RefID () string {
109
+ func (sf * CommitSubModuleFile ) RefID () string {
186
110
return sf .refID
187
111
}
0 commit comments