@@ -69,7 +69,8 @@ func LsRemote(url string, opts ...LsRemoteOptions) ([]*Reference, error) {
69
69
return refs , nil
70
70
}
71
71
72
- // IsURLAccessible returns true if given remote URL is accessible via Git.
72
+ // IsURLAccessible returns true if given remote URL is accessible via Git
73
+ // within given timeout.
73
74
func IsURLAccessible (timeout time.Duration , url string ) bool {
74
75
_ , err := LsRemote (url , LsRemoteOptions {
75
76
Patterns : []string {"HEAD" },
@@ -90,8 +91,8 @@ type AddRemoteOptions struct {
90
91
Timeout time.Duration
91
92
}
92
93
93
- // AddRemote adds a new remote to the repository.
94
- func ( r * Repository ) AddRemote ( name , url string , opts ... AddRemoteOptions ) error {
94
+ // AddRemote adds a new remote to the repository in given path .
95
+ func RepoAddRemote ( repoPath , name , url string , opts ... AddRemoteOptions ) error {
95
96
var opt AddRemoteOptions
96
97
if len (opts ) > 0 {
97
98
opt = opts [0 ]
@@ -105,10 +106,15 @@ func (r *Repository) AddRemote(name, url string, opts ...AddRemoteOptions) error
105
106
cmd .AddArgs ("--mirror=fetch" )
106
107
}
107
108
108
- _ , err := cmd .AddArgs (name , url ).RunInDirWithTimeout (opt .Timeout , r . path )
109
+ _ , err := cmd .AddArgs (name , url ).RunInDirWithTimeout (opt .Timeout , repoPath )
109
110
return err
110
111
}
111
112
113
+ // AddRemote adds a new remote to the repository.
114
+ func (r * Repository ) AddRemote (name , url string , opts ... AddRemoteOptions ) error {
115
+ return RepoAddRemote (r .path , name , url , opts ... )
116
+ }
117
+
112
118
// RemoveRemoteOptions contains arguments for removing a remote from the repository.
113
119
// Docs: https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emremoveem
114
120
type RemoveRemoteOptions struct {
@@ -117,14 +123,14 @@ type RemoveRemoteOptions struct {
117
123
Timeout time.Duration
118
124
}
119
125
120
- // RemoveRemote removes a remote from the repository.
121
- func ( r * Repository ) RemoveRemote ( name string , opts ... RemoveRemoteOptions ) error {
126
+ // RemoveRemote removes a remote from the repository in given path .
127
+ func RepoRemoveRemote ( repoPath , name string , opts ... RemoveRemoteOptions ) error {
122
128
var opt RemoveRemoteOptions
123
129
if len (opts ) > 0 {
124
130
opt = opts [0 ]
125
131
}
126
132
127
- _ , err := NewCommand ("remote" , "remove" , name ).RunInDirWithTimeout (opt .Timeout , r . path )
133
+ _ , err := NewCommand ("remote" , "remove" , name ).RunInDirWithTimeout (opt .Timeout , repoPath )
128
134
if err != nil {
129
135
if strings .Contains (err .Error (), "fatal: No such remote" ) {
130
136
return ErrRemoteNotExist
@@ -133,3 +139,8 @@ func (r *Repository) RemoveRemote(name string, opts ...RemoveRemoteOptions) erro
133
139
}
134
140
return nil
135
141
}
142
+
143
+ // RemoveRemote removes a remote from the repository.
144
+ func (r * Repository ) RemoveRemote (name string , opts ... RemoveRemoteOptions ) error {
145
+ return RepoRemoveRemote (r .path , name , opts ... )
146
+ }
0 commit comments