mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-26 12:27:06 +00:00 
			
		
		
		
	modes/repo: incorrect SSH clone URL for #742
This commit is contained in:
		
							
								
								
									
										2
									
								
								gogs.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								gogs.go
									
									
									
									
									
								
							| @@ -17,7 +17,7 @@ import ( | |||||||
| 	"github.com/gogits/gogs/modules/setting" | 	"github.com/gogits/gogs/modules/setting" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| const APP_VER = "0.5.8.1212 Beta" | const APP_VER = "0.5.8.1213 Beta" | ||||||
|  |  | ||||||
| func init() { | func init() { | ||||||
| 	runtime.GOMAXPROCS(runtime.NumCPU()) | 	runtime.GOMAXPROCS(runtime.NumCPU()) | ||||||
|   | |||||||
| @@ -241,6 +241,27 @@ func IsRepositoryExist(u *User, repoName string) (bool, error) { | |||||||
| 	return com.IsDir(RepoPath(u.Name, repoName)), nil | 	return com.IsDir(RepoPath(u.Name, repoName)), nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // CloneLink represents different types of clone URLs of repository. | ||||||
|  | type CloneLink struct { | ||||||
|  | 	SSH   string | ||||||
|  | 	HTTPS string | ||||||
|  | 	Git   string | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // CloneLink returns clone URLs of repository. | ||||||
|  | func (repo *Repository) CloneLink() (cl CloneLink, err error) { | ||||||
|  | 	if err = repo.GetOwner(); err != nil { | ||||||
|  | 		return cl, err | ||||||
|  | 	} | ||||||
|  | 	if setting.SshPort != 22 { | ||||||
|  | 		cl.SSH = fmt.Sprintf("ssh://%s@%s:%d/%s/%s.git", setting.RunUser, setting.Domain, setting.SshPort, repo.Owner.LowerName, repo.LowerName) | ||||||
|  | 	} else { | ||||||
|  | 		cl.SSH = fmt.Sprintf("%s@%s:%s/%s.git", setting.RunUser, setting.Domain, repo.Owner.LowerName, repo.LowerName) | ||||||
|  | 	} | ||||||
|  | 	cl.HTTPS = fmt.Sprintf("%s%s/%s.git", setting.AppUrl, repo.Owner.LowerName, repo.LowerName) | ||||||
|  | 	return cl, nil | ||||||
|  | } | ||||||
|  |  | ||||||
| var ( | var ( | ||||||
| 	illegalEquals  = []string{"debug", "raw", "install", "api", "avatar", "user", "org", "help", "stars", "issues", "pulls", "commits", "repo", "template", "admin", "new"} | 	illegalEquals  = []string{"debug", "raw", "install", "api", "avatar", "user", "org", "help", "stars", "issues", "pulls", "commits", "repo", "template", "admin", "new"} | ||||||
| 	illegalSuffixs = []string{".git", ".keys"} | 	illegalSuffixs = []string{".git", ".keys"} | ||||||
|   | |||||||
| @@ -57,11 +57,7 @@ type Context struct { | |||||||
| 		TreeName     string | 		TreeName     string | ||||||
| 		CommitId     string | 		CommitId     string | ||||||
| 		RepoLink     string | 		RepoLink     string | ||||||
| 		CloneLink   struct { | 		CloneLink    models.CloneLink | ||||||
| 			SSH   string |  | ||||||
| 			HTTPS string |  | ||||||
| 			Git   string |  | ||||||
| 		} |  | ||||||
| 		CommitsCount int | 		CommitsCount int | ||||||
| 		Mirror       *models.Mirror | 		Mirror       *models.Mirror | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -386,12 +386,11 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { | |||||||
| 		ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner | 		ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner | ||||||
| 		ctx.Data["IsRepositoryTrueOwner"] = ctx.Repo.IsTrueOwner | 		ctx.Data["IsRepositoryTrueOwner"] = ctx.Repo.IsTrueOwner | ||||||
|  |  | ||||||
| 		if setting.SshPort != 22 { | 		ctx.Repo.CloneLink, err = repo.CloneLink() | ||||||
| 			ctx.Repo.CloneLink.SSH = fmt.Sprintf("ssh://%s@%s:%d/%s/%s.git", setting.RunUser, setting.Domain, setting.SshPort, u.LowerName, repo.LowerName) | 		if err != nil { | ||||||
| 		} else { | 			ctx.Handle(500, "CloneLink", err) | ||||||
| 			ctx.Repo.CloneLink.SSH = fmt.Sprintf("%s@%s:%s/%s.git", setting.RunUser, setting.Domain, u.LowerName, repo.LowerName) | 			return | ||||||
| 		} | 		} | ||||||
| 		ctx.Repo.CloneLink.HTTPS = fmt.Sprintf("%s%s/%s.git", setting.AppUrl, u.LowerName, repo.LowerName) |  | ||||||
| 		ctx.Data["CloneLink"] = ctx.Repo.CloneLink | 		ctx.Data["CloneLink"] = ctx.Repo.CloneLink | ||||||
|  |  | ||||||
| 		if ctx.Repo.Repository.IsGoget { | 		if ctx.Repo.Repository.IsGoget { | ||||||
|   | |||||||
| @@ -23,20 +23,19 @@ import ( | |||||||
|  |  | ||||||
| // ToApiRepository converts repository to API format. | // ToApiRepository converts repository to API format. | ||||||
| func ToApiRepository(owner *models.User, repo *models.Repository, permission api.Permission) *api.Repository { | func ToApiRepository(owner *models.User, repo *models.Repository, permission api.Permission) *api.Repository { | ||||||
| 	sshUrlFmt := "%s@%s:%s/%s.git" | 	cl, err := repo.CloneLink() | ||||||
| 	if setting.SshPort != 22 { | 	if err != nil { | ||||||
| 		sshUrlFmt = "ssh://%s@%s:%d/%s/%s.git" | 		log.Error(4, "CloneLink: %v", err) | ||||||
| 	} | 	} | ||||||
| 	htmlUrl := setting.AppUrl + owner.Name + "/" + repo.Name |  | ||||||
| 	return &api.Repository{ | 	return &api.Repository{ | ||||||
| 		Id:          repo.Id, | 		Id:          repo.Id, | ||||||
| 		Owner:       *ToApiUser(owner), | 		Owner:       *ToApiUser(owner), | ||||||
| 		FullName:    owner.Name + "/" + repo.Name, | 		FullName:    owner.Name + "/" + repo.Name, | ||||||
| 		Private:     repo.IsPrivate, | 		Private:     repo.IsPrivate, | ||||||
| 		Fork:        repo.IsFork, | 		Fork:        repo.IsFork, | ||||||
| 		HtmlUrl:     htmlUrl, | 		HtmlUrl:     setting.AppUrl + owner.Name + "/" + repo.Name, | ||||||
| 		SshUrl:      fmt.Sprintf(sshUrlFmt, setting.RunUser, setting.Domain, owner.LowerName, repo.LowerName), | 		CloneUrl:    cl.HTTPS, | ||||||
| 		CloneUrl:    htmlUrl + ".git", | 		SshUrl:      cl.SSH, | ||||||
| 		Permissions: permission, | 		Permissions: permission, | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1 +1 @@ | |||||||
| 0.5.8.1212 Beta | 0.5.8.1213 Beta | ||||||
		Reference in New Issue
	
	Block a user
	 Unknwon
					Unknwon