Skip to content

Commit ac8a62a

Browse files
committed
Use proxy for pull mirror (go-gitea#22771)
- Backport go-gitea#22771 - Use the proxy (if one is specified) for pull mirrors syncs. - Pulled the code from https://github.com/go-gitea/gitea/blob/c2774d9e80d9a436d9c2044960369c4db227e3a0/modules/git/repo.go#L164-L170 - Downstream issue: https://codeberg.org/forgejo/forgejo/issues/302
1 parent 2e12161 commit ac8a62a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Diff for: services/mirror/mirror_pull.go

+9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"code.gitea.io/gitea/modules/log"
2020
"code.gitea.io/gitea/modules/notification"
2121
"code.gitea.io/gitea/modules/process"
22+
"code.gitea.io/gitea/modules/proxy"
2223
repo_module "code.gitea.io/gitea/modules/repository"
2324
"code.gitea.io/gitea/modules/setting"
2425
"code.gitea.io/gitea/modules/timeutil"
@@ -216,13 +217,21 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
216217
return nil, false
217218
}
218219

220+
envs := []string{}
221+
if strings.EqualFold(remoteURL.Scheme, "http") || strings.EqualFold(remoteURL.Scheme, "https") {
222+
if proxy.Match(remoteURL.Host) {
223+
envs = append(envs, fmt.Sprintf("https_proxy=%s", proxy.GetProxyURL()))
224+
}
225+
}
226+
219227
stdoutBuilder := strings.Builder{}
220228
stderrBuilder := strings.Builder{}
221229
if err := git.NewCommand(ctx, gitArgs...).
222230
SetDescription(fmt.Sprintf("Mirror.runSync: %s", m.Repo.FullName())).
223231
Run(&git.RunOpts{
224232
Timeout: timeout,
225233
Dir: repoPath,
234+
Env: envs,
226235
Stdout: &stdoutBuilder,
227236
Stderr: &stderrBuilder,
228237
}); err != nil {

0 commit comments

Comments
 (0)