File tree Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -22,4 +22,6 @@ type RepoInfo struct {
2222 Version string
2323 // Upstream remote name
2424 Upstream string
25+ // Remotes name and url mapping.
26+ Remotes map [string ]string
2527}
Original file line number Diff line number Diff line change @@ -11,6 +11,16 @@ const (
1111// RemoteInfos map. key is type name(see RemoteTypePush)
1212type RemoteInfos map [string ]* RemoteInfo
1313
14+ // FetchInfo fetch remote info
15+ func (rs RemoteInfos ) FetchInfo () * RemoteInfo {
16+ return rs [RemoteTypeFetch ]
17+ }
18+
19+ // PushInfo push remote info
20+ func (rs RemoteInfos ) PushInfo () * RemoteInfo {
21+ return rs [RemoteTypePush ]
22+ }
23+
1424// RemoteInfo struct
1525//
1626// - http: "https://github.com/gookit/gitw.git"
Original file line number Diff line number Diff line change @@ -53,6 +53,9 @@ type Repo struct {
5353 // remoteNames
5454 remoteNames []string
5555 // remoteInfosMp
56+ //
57+ // Example:
58+ // {origin: {fetch: remote info, push: remote info}}
5659 remoteInfosMp map [string ]RemoteInfos
5760
5861 // cache some information of the repo
@@ -117,7 +120,7 @@ func (r *Repo) Info() *RepoInfo {
117120 Upstream : r .UpstreamPath (),
118121 }
119122
120- rt := r .loadRemoteInfos ().DefaultRemoteInfo ()
123+ rt := r .loadRemoteInfos ().FirstRemoteInfo ()
121124 if rt == nil {
122125 return ri
123126 }
@@ -126,6 +129,12 @@ func (r *Repo) Info() *RepoInfo {
126129 ri .Path = rt .Path ()
127130 ri .URL = rt .URLOrBuild ()
128131
132+ remotes := make (map [string ]string )
133+ for name , infos := range r .remoteInfosMp {
134+ remotes [name ] = infos .FetchInfo ().URL
135+ }
136+
137+ ri .Remotes = remotes
129138 return ri
130139}
131140
@@ -480,7 +489,7 @@ func (r *Repo) UpstreamPath() string {
480489 // RUN: git rev-parse --abbrev-ref @{u}
481490 if path == "" {
482491 path = r .Git ().RevParse ("--abbrev-ref" , "@{u}" ).SafeOutput ()
483- r .cache .Set (cacheUpstreamPath , path )
492+ r .cache .Set (cacheUpstreamPath , strings . TrimSpace ( path ) )
484493 }
485494
486495 return path
You can’t perform that action at this time.
0 commit comments