@@ -178,7 +178,12 @@ func remoteCommand(args []string) error { |
| 178 |
if fetchURL == "" { |
178 |
if fetchURL == "" { |
| 179 |
return fmt.Errorf("public URL is required") |
179 |
return fmt.Errorf("public URL is required") |
| 180 |
} |
180 |
} |
| 181 |
if err := runGit("remote", "add", "--", name, fetchURL); err != nil { |
181 |
remoteArgs := []string{"remote", "add"} |
|
|
182 |
if isMirrorRepository() { |
|
|
183 |
remoteArgs = append(remoteArgs, "--mirror=push") |
|
|
184 |
} |
|
|
185 |
remoteArgs = append(remoteArgs, "--", name, fetchURL) |
|
|
186 |
if err := runGit(remoteArgs...); err != nil { |
| 182 |
return err |
187 |
return err |
| 183 |
} |
188 |
} |
| 184 |
if err := runGit("config", "--add", "remote."+name+".pushurl", pushURL); err != nil { |
189 |
if err := runGit("config", "--add", "remote."+name+".pushurl", pushURL); err != nil { |
@@ -188,6 +193,20 @@ func remoteCommand(args []string) error { |
| 188 |
return nil |
193 |
return nil |
| 189 |
} |
194 |
} |
| 190 |
|
195 |
|
|
|
196 |
func isMirrorRepository() bool { |
|
|
197 |
out, err := gitOutput("config", "--type=bool", "--get-regexp", `^remote\..*\.mirror$`) |
|
|
198 |
if err != nil { |
|
|
199 |
return false |
|
|
200 |
} |
|
|
201 |
for _, line := range strings.Split(string(out), "\n") { |
|
|
202 |
fields := strings.Fields(line) |
|
|
203 |
if len(fields) == 2 && fields[1] == "true" { |
|
|
204 |
return true |
|
|
205 |
} |
|
|
206 |
} |
|
|
207 |
return false |
|
|
208 |
} |
|
|
209 |
|
| 191 |
func runGit(args ...string) error { |
210 |
func runGit(args ...string) error { |
| 192 |
// #nosec G204 G702 -- arguments are passed directly to Git without a shell. |
211 |
// #nosec G204 G702 -- arguments are passed directly to Git without a shell. |
| 193 |
cmd := exec.Command("git", args...) |
212 |
cmd := exec.Command("git", args...) |