@@ -19,16 +19,16 @@ type LsRemoteOptions struct {
19
19
Tags bool
20
20
// Indicates whether to not show peeled tags or pseudorefs.
21
21
Refs bool
22
- // The URL of the remote repository .
23
- URL string
22
+ // The list of patterns to filter results .
23
+ Patterns [] string
24
24
// The timeout duration before giving up. The default timeout duration will be used when not supplied.
25
25
Timeout time.Duration
26
26
}
27
27
28
28
// LsRemote returns a list references in the remote repository.
29
- func LsRemote (opts ... LsRemoteOptions ) ([]* Reference , error ) {
29
+ func LsRemote (url string , opts ... LsRemoteOptions ) ([]* Reference , error ) {
30
30
var opt LsRemoteOptions
31
- if len (opts ) > 1 {
31
+ if len (opts ) > 0 {
32
32
opt = opts [0 ]
33
33
}
34
34
@@ -42,8 +42,9 @@ func LsRemote(opts ...LsRemoteOptions) ([]*Reference, error) {
42
42
if opt .Refs {
43
43
cmd .AddArgs ("--refs" )
44
44
}
45
- if opt .URL != "" {
46
- cmd .AddArgs (opt .URL )
45
+ cmd .AddArgs (url )
46
+ if len (opt .Patterns ) > 0 {
47
+ cmd .AddArgs (opt .Patterns ... )
47
48
}
48
49
49
50
stdout , err := cmd .RunWithTimeout (opt .Timeout )
@@ -69,14 +70,15 @@ func LsRemote(opts ...LsRemoteOptions) ([]*Reference, error) {
69
70
70
71
// IsURLAccessible returns true if given remote URL is accessible via Git.
71
72
func IsURLAccessible (timeout time.Duration , url string ) bool {
72
- _ , err := LsRemote (LsRemoteOptions {
73
- URL : url ,
74
- Timeout : timeout ,
73
+ _ , err := LsRemote (url , LsRemoteOptions {
74
+ Patterns : [] string { "HEAD" } ,
75
+ Timeout : timeout ,
75
76
})
76
77
return err == nil
77
78
}
78
79
79
80
// AddRemoteOptions contains options to add a remote address.
81
+ // Docs: https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emaddem
80
82
type AddRemoteOptions struct {
81
83
// Indicates whether to execute git fetch after the remote information is set up.
82
84
Fetch bool
@@ -89,7 +91,7 @@ type AddRemoteOptions struct {
89
91
// AddRemote adds a new remote to the repository.
90
92
func (r * Repository ) AddRemote (name , url string , opts ... AddRemoteOptions ) error {
91
93
var opt AddRemoteOptions
92
- if len (opts ) > 1 {
94
+ if len (opts ) > 0 {
93
95
opt = opts [0 ]
94
96
}
95
97
@@ -115,12 +117,15 @@ type RemoveRemoteOptions struct {
115
117
// RemoveRemote removes a remote from the repository.
116
118
func (r * Repository ) RemoveRemote (name string , opts ... RemoveRemoteOptions ) error {
117
119
var opt RemoveRemoteOptions
118
- if len (opts ) > 1 {
120
+ if len (opts ) > 0 {
119
121
opt = opts [0 ]
120
122
}
121
123
122
124
_ , err := NewCommand ("remote" , "remove" , name ).RunInDirWithTimeout (opt .Timeout , r .path )
123
- if err != nil && ! strings .Contains (err .Error (), "fatal: No such remote" ) {
125
+ if err != nil {
126
+ if strings .Contains (err .Error (), "fatal: No such remote" ) {
127
+ return ErrRemoteNotExist
128
+ }
124
129
return err
125
130
}
126
131
return nil
0 commit comments