mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	Fix some mirror bugs (#18649)
* Fix some mirror bugs * Remove unnecessary code * Fix lint * rename stdard url * Allow more charactors in git ssh protocol url * improve the detection * support ipv6 for git url parse * Fix bug * Fix template * Fix bug * fix template * Fix tmpl * Fix tmpl * Fix parse ssh with interface * Rename functions name Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
		@@ -32,6 +32,7 @@ import (
 | 
			
		||||
	"code.gitea.io/gitea/modules/base"
 | 
			
		||||
	"code.gitea.io/gitea/modules/emoji"
 | 
			
		||||
	"code.gitea.io/gitea/modules/git"
 | 
			
		||||
	giturl "code.gitea.io/gitea/modules/git/url"
 | 
			
		||||
	"code.gitea.io/gitea/modules/json"
 | 
			
		||||
	"code.gitea.io/gitea/modules/log"
 | 
			
		||||
	"code.gitea.io/gitea/modules/markup"
 | 
			
		||||
@@ -971,20 +972,35 @@ type remoteAddress struct {
 | 
			
		||||
	Password string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func mirrorRemoteAddress(ctx context.Context, m repo_model.RemoteMirrorer) remoteAddress {
 | 
			
		||||
func mirrorRemoteAddress(ctx context.Context, m *repo_model.Repository, remoteName string) remoteAddress {
 | 
			
		||||
	a := remoteAddress{}
 | 
			
		||||
 | 
			
		||||
	u, err := git.GetRemoteAddress(ctx, m.GetRepository().RepoPath(), m.GetRemoteName())
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Error("GetRemoteAddress %v", err)
 | 
			
		||||
	if !m.IsMirror {
 | 
			
		||||
		return a
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if u.User != nil {
 | 
			
		||||
		a.Username = u.User.Username()
 | 
			
		||||
		a.Password, _ = u.User.Password()
 | 
			
		||||
	remoteURL := m.OriginalURL
 | 
			
		||||
	if remoteURL == "" {
 | 
			
		||||
		var err error
 | 
			
		||||
		remoteURL, err = git.GetRemoteAddress(ctx, m.RepoPath(), remoteName)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Error("GetRemoteURL %v", err)
 | 
			
		||||
			return a
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	u, err := giturl.Parse(remoteURL)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Error("giturl.Parse %v", err)
 | 
			
		||||
		return a
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if u.Scheme != "ssh" && u.Scheme != "file" {
 | 
			
		||||
		if u.User != nil {
 | 
			
		||||
			a.Username = u.User.Username()
 | 
			
		||||
			a.Password, _ = u.User.Password()
 | 
			
		||||
		}
 | 
			
		||||
		u.User = nil
 | 
			
		||||
	}
 | 
			
		||||
	u.User = nil
 | 
			
		||||
	a.Address = u.String()
 | 
			
		||||
 | 
			
		||||
	return a
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user