|
@@ -13,6 +13,8 @@ import (
|
|
"github.com/go-xorm/xorm"
|
|
"github.com/go-xorm/xorm"
|
|
"gopkg.in/ini.v1"
|
|
"gopkg.in/ini.v1"
|
|
|
|
|
|
|
|
+ "github.com/gogits/git-module"
|
|
|
|
+
|
|
"github.com/gogits/gogs/modules/log"
|
|
"github.com/gogits/gogs/modules/log"
|
|
"github.com/gogits/gogs/modules/process"
|
|
"github.com/gogits/gogs/modules/process"
|
|
"github.com/gogits/gogs/modules/setting"
|
|
"github.com/gogits/gogs/modules/setting"
|
|
@@ -104,6 +106,12 @@ func (m *Mirror) Address() string {
|
|
return HandleCloneUserCredentials(m.address, false)
|
|
return HandleCloneUserCredentials(m.address, false)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// MosaicsAddress returns mirror address from Git repository config with credentials under mosaics.
|
|
|
|
+func (m *Mirror) MosaicsAddress() string {
|
|
|
|
+ m.readAddress()
|
|
|
|
+ return HandleCloneUserCredentials(m.address, true)
|
|
|
|
+}
|
|
|
|
+
|
|
// FullAddress returns mirror address from Git repository config.
|
|
// FullAddress returns mirror address from Git repository config.
|
|
func (m *Mirror) FullAddress() string {
|
|
func (m *Mirror) FullAddress() string {
|
|
m.readAddress()
|
|
m.readAddress()
|
|
@@ -128,11 +136,23 @@ func (m *Mirror) runSync() bool {
|
|
wikiPath := m.Repo.WikiPath()
|
|
wikiPath := m.Repo.WikiPath()
|
|
timeout := time.Duration(setting.Git.Timeout.Mirror) * time.Second
|
|
timeout := time.Duration(setting.Git.Timeout.Mirror) * time.Second
|
|
|
|
|
|
|
|
+ // Do a fast-fail testing against on repository URL to ensure it is accessible under
|
|
|
|
+ // good condition to prevent long blocking on URL resolution without syncing anything.
|
|
|
|
+ if !git.IsRepoURLAccessible(git.NetworkOptions{
|
|
|
|
+ URL: m.FullAddress(),
|
|
|
|
+ Timeout: 10 * time.Second,
|
|
|
|
+ }) {
|
|
|
|
+ desc := fmt.Sprintf("Mirror repository URL is not accessible: %s", m.MosaicsAddress())
|
|
|
|
+ if err := CreateRepositoryNotice(desc); err != nil {
|
|
|
|
+ log.Error(4, "CreateRepositoryNotice: %v", err)
|
|
|
|
+ }
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+
|
|
gitArgs := []string{"remote", "update"}
|
|
gitArgs := []string{"remote", "update"}
|
|
if m.EnablePrune {
|
|
if m.EnablePrune {
|
|
gitArgs = append(gitArgs, "--prune")
|
|
gitArgs = append(gitArgs, "--prune")
|
|
}
|
|
}
|
|
-
|
|
|
|
if _, stderr, err := process.ExecDir(
|
|
if _, stderr, err := process.ExecDir(
|
|
timeout, repoPath, fmt.Sprintf("Mirror.runSync: %s", repoPath),
|
|
timeout, repoPath, fmt.Sprintf("Mirror.runSync: %s", repoPath),
|
|
"git", gitArgs...); err != nil {
|
|
"git", gitArgs...); err != nil {
|