4
4
5
5
package git
6
6
7
- import (
8
- "strings"
9
- "sync"
10
- )
11
-
12
7
// Submodule contains information of a Git submodule.
13
8
type Submodule struct {
14
9
name string
@@ -25,63 +20,15 @@ func (s *Submodule) URL() string {
25
20
return s .url
26
21
}
27
22
28
- // SubmoduleFile is a file with submodule type.
29
- type SubmoduleFile struct {
30
- * Commit
31
-
32
- refID string
33
- refURL string
34
- refURLOnce sync.Once
35
- }
36
-
37
- // RefURL guesses and returns the reference URL.
38
- func (f * SubmoduleFile ) RefURL (urlPrefix , parentPath string ) string {
39
- f .refURLOnce .Do (func () {
40
- f .refURL = strings .TrimSuffix (f .refURL , ".git" )
41
-
42
- // git://xxx/user/repo
43
- if strings .HasPrefix (f .refURL , "git://" ) {
44
- f .refURL = "http://" + strings .TrimPrefix (f .refURL , "git://" )
45
- return
46
- }
23
+ // SubmoduleEntry is an tree entry in submodule type.
24
+ type SubmoduleEntry struct {
25
+ id * SHA1
47
26
48
- // http[s]://xxx/user/repo
49
- if strings .HasPrefix (f .refURL , "http://" ) || strings .HasPrefix (f .refURL , "https://" ) {
50
- return
51
- }
52
-
53
- // Relative URL prefix check (according to Git submodule documentation)
54
- if strings .HasPrefix (f .refURL , "./" ) || strings .HasPrefix (f .refURL , "../" ) {
55
- // ...construct and return correct submodule URL here.
56
- idx := strings .Index (parentPath , "/src/" )
57
- if idx == - 1 {
58
- return
59
- }
60
- f .refURL = strings .TrimSuffix (urlPrefix , "/" ) + parentPath [:idx ] + "/" + f .refURL
61
- return
62
- }
63
-
64
- // sysuser@xxx:user/repo
65
- i := strings .Index (f .refURL , "@" )
66
- j := strings .LastIndex (f .refURL , ":" )
67
-
68
- // Only process when i < j because git+ssh://[email protected] /npploader.git
69
- if i > - 1 && j > - 1 && i < j {
70
- // Fix problem with reverse proxy works only with local server
71
- if strings .Contains (urlPrefix , f .refURL [i + 1 :j ]) {
72
- f .refURL = urlPrefix + f .refURL [j + 1 :]
73
- return
74
- }
75
-
76
- f .refURL = "http://" + f .refURL [i + 1 :j ] + "/" + f .refURL [j + 1 :]
77
- return
78
- }
79
- })
80
-
81
- return f .refURL
27
+ * Submodule
28
+ * Commit
82
29
}
83
30
84
- // RefID returns the reference ID .
85
- func (f * SubmoduleFile ) RefID () string {
86
- return f .refID
31
+ // ID returns the ID of the submodule file .
32
+ func (f * SubmoduleEntry ) ID () * SHA1 {
33
+ return f .id
87
34
}
0 commit comments