Skip to content

Commit a5604b1

Browse files
jeblairlafriks
authored andcommitted
Fix renames over redirects (#6216)
In #6211, we started creating repo_redirects for ownership transfers, however that opens an edge case where a user might perform the following sequence: rename org1/repo1 -> org1/repo2 (creates org1/repo1 redirect) transfer org2/repo1 -> org1/repo1 (org1/repo1 redirect continues to exist) rename org1/repo1 -> org1/repo3 (fails due to existing org1/repo1 redirect) This change ensures that each time we rename or transfer a repo, we delete any existing redirects at the target location. This already happens when a new repo is created. By doing this we ensure that we'll never have both a repo and a redirect at the same location. Signed-off-by: James E. Blair <[email protected]>
1 parent b28e527 commit a5604b1

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

models/repo.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,11 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error
15641564
}
15651565
}
15661566

1567+
// If there was previously a redirect at this location, remove it.
1568+
if err = deleteRepoRedirect(sess, newOwner.ID, repo.Name); err != nil {
1569+
return fmt.Errorf("delete repo redirect: %v", err)
1570+
}
1571+
15671572
return sess.Commit()
15681573
}
15691574

@@ -1614,7 +1619,18 @@ func ChangeRepositoryName(u *User, oldRepoName, newRepoName string) (err error)
16141619
RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath())
16151620
}
16161621

1617-
return nil
1622+
sess := x.NewSession()
1623+
defer sess.Close()
1624+
if err = sess.Begin(); err != nil {
1625+
return fmt.Errorf("sess.Begin: %v", err)
1626+
}
1627+
1628+
// If there was previously a redirect at this location, remove it.
1629+
if err = deleteRepoRedirect(sess, u.ID, newRepoName); err != nil {
1630+
return fmt.Errorf("delete repo redirect: %v", err)
1631+
}
1632+
1633+
return sess.Commit()
16181634
}
16191635

16201636
func getRepositoriesByForkID(e Engine, forkID int64) ([]*Repository, error) {

0 commit comments

Comments
 (0)