@@ -133,6 +133,26 @@ func earlyResponseForGoGetMeta(ctx *Context) {
133
133
})))
134
134
}
135
135
136
+ // RedirectToRepo redirect to a differently-named repository
137
+ func RedirectToRepo (ctx * Context , redirectRepoID int64 ) {
138
+ ownerName := ctx .Params (":username" )
139
+ previousRepoName := ctx .Params (":reponame" )
140
+
141
+ repo , err := models .GetRepositoryByID (redirectRepoID )
142
+ if err != nil {
143
+ ctx .Handle (500 , "GetRepositoryByID" , err )
144
+ return
145
+ }
146
+
147
+ redirectPath := strings .Replace (
148
+ ctx .Req .URL .Path ,
149
+ fmt .Sprintf ("%s/%s" , ownerName , previousRepoName ),
150
+ fmt .Sprintf ("%s/%s" , ownerName , repo .Name ),
151
+ 1 ,
152
+ )
153
+ ctx .Redirect (redirectPath )
154
+ }
155
+
136
156
// RepoAssignment returns a macaron to handle repository assignment
137
157
func RepoAssignment (args ... bool ) macaron.Handler {
138
158
return func (ctx * Context ) {
@@ -176,11 +196,18 @@ func RepoAssignment(args ...bool) macaron.Handler {
176
196
repo , err := models .GetRepositoryByName (owner .ID , repoName )
177
197
if err != nil {
178
198
if models .IsErrRepoNotExist (err ) {
179
- if ctx .Query ("go-get" ) == "1" {
180
- earlyResponseForGoGetMeta (ctx )
181
- return
199
+ redirectRepoID , err := models .LookupRepoRedirect (owner .ID , repoName )
200
+ if err == nil {
201
+ RedirectToRepo (ctx , redirectRepoID )
202
+ } else if models .IsErrRepoRedirectNotExist (err ) {
203
+ if ctx .Query ("go-get" ) == "1" {
204
+ earlyResponseForGoGetMeta (ctx )
205
+ return
206
+ }
207
+ ctx .Handle (404 , "GetRepositoryByName" , err )
208
+ } else {
209
+ ctx .Handle (500 , "LookupRepoRedirect" , err )
182
210
}
183
- ctx .Handle (404 , "GetRepositoryByName" , err )
184
211
} else {
185
212
ctx .Handle (500 , "GetRepositoryByName" , err )
186
213
}
0 commit comments