@@ -19,23 +19,27 @@ func getRepoLock(localRepoRoot string) bool {
19
19
return ! loaded
20
20
}
21
21
22
+ type getInfo struct {
23
+ localRepository * LocalRepository
24
+ }
25
+
22
26
type getter struct {
23
27
update , shallow , silent , ssh , recursive , bare bool
24
28
vcs , branch string
25
29
}
26
30
27
- func (g * getter ) get (argURL string ) error {
31
+ func (g * getter ) get (argURL string ) ( getInfo , error ) {
28
32
u , err := newURL (argURL , g .ssh , false )
29
33
if err != nil {
30
- return fmt .Errorf ("could not parse URL %q: %w" , argURL , err )
34
+ return getInfo {}, fmt .Errorf ("could not parse URL %q: %w" , argURL , err )
31
35
}
32
36
branch := g .branch
33
37
if pos := strings .LastIndexByte (u .Path , '@' ); pos >= 0 {
34
38
u .Path , branch = u .Path [:pos ], u .Path [pos + 1 :]
35
39
}
36
40
remote , err := NewRemoteRepository (u )
37
41
if err != nil {
38
- return err
42
+ return getInfo {}, err
39
43
}
40
44
41
45
return g .getRemoteRepository (remote , branch )
@@ -44,11 +48,14 @@ func (g *getter) get(argURL string) error {
44
48
// getRemoteRepository clones or updates a remote repository remote.
45
49
// If doUpdate is true, updates the locally cloned repository. Otherwise does nothing.
46
50
// If isShallow is true, does shallow cloning. (no effect if already cloned or the VCS is Mercurial and git-svn)
47
- func (g * getter ) getRemoteRepository (remote RemoteRepository , branch string ) error {
51
+ func (g * getter ) getRemoteRepository (remote RemoteRepository , branch string ) ( getInfo , error ) {
48
52
remoteURL := remote .URL ()
49
53
local , err := LocalRepositoryFromURL (remoteURL , g .bare )
50
54
if err != nil {
51
- return err
55
+ return getInfo {}, err
56
+ }
57
+ info := getInfo {
58
+ localRepository : local ,
52
59
}
53
60
54
61
var (
@@ -63,7 +70,7 @@ func (g *getter) getRemoteRepository(remote RemoteRepository, branch string) err
63
70
err = nil
64
71
}
65
72
if err != nil {
66
- return err
73
+ return getInfo {}, err
67
74
}
68
75
}
69
76
@@ -82,7 +89,7 @@ func (g *getter) getRemoteRepository(remote RemoteRepository, branch string) err
82
89
if ! ok {
83
90
vcs , repoURL , err = remote .VCS ()
84
91
if err != nil {
85
- return err
92
+ return getInfo {}, err
86
93
}
87
94
}
88
95
if l := detectLocalRepoRoot (remoteURL .Path , repoURL .Path ); l != "" {
@@ -97,40 +104,41 @@ func (g *getter) getRemoteRepository(remote RemoteRepository, branch string) err
97
104
repoURL , _ = url .Parse (remoteURL .Opaque )
98
105
}
99
106
if getRepoLock (localRepoRoot ) {
100
- return vcs .Clone (& vcsGetOption {
101
- url : repoURL ,
102
- dir : localRepoRoot ,
103
- shallow : g .shallow ,
104
- silent : g .silent ,
105
- branch : branch ,
106
- recursive : g .recursive ,
107
- bare : g .bare ,
108
- })
107
+ return info ,
108
+ vcs .Clone (& vcsGetOption {
109
+ url : repoURL ,
110
+ dir : localRepoRoot ,
111
+ shallow : g .shallow ,
112
+ silent : g .silent ,
113
+ branch : branch ,
114
+ recursive : g .recursive ,
115
+ bare : g .bare ,
116
+ })
109
117
}
110
- return nil
118
+ return info , nil
111
119
case g .update :
112
120
logger .Log ("update" , fpath )
113
121
vcs , localRepoRoot := local .VCS ()
114
122
if vcs == nil {
115
- return fmt .Errorf ("failed to detect VCS for %q" , fpath )
123
+ return getInfo {}, fmt .Errorf ("failed to detect VCS for %q" , fpath )
116
124
}
117
125
repoURL := remoteURL
118
126
if remoteURL .Scheme == "codecommit" {
119
127
repoURL , _ = url .Parse (remoteURL .Opaque )
120
128
}
121
129
if getRepoLock (localRepoRoot ) {
122
- return vcs .Update (& vcsGetOption {
130
+ return info , vcs .Update (& vcsGetOption {
123
131
url : repoURL ,
124
132
dir : localRepoRoot ,
125
133
silent : g .silent ,
126
134
recursive : g .recursive ,
127
135
bare : g .bare ,
128
136
})
129
137
}
130
- return nil
138
+ return info , nil
131
139
}
132
140
logger .Log ("exists" , fpath )
133
- return nil
141
+ return info , nil
134
142
}
135
143
136
144
func detectLocalRepoRoot (remotePath , repoPath string ) string {
0 commit comments