summaryrefslogtreecommitdiffstats
path: root/models/repo.go
diff options
context:
space:
mode:
authorJames E. Blair <corvus@inaugust.com>2019-03-02 05:07:19 -0800
committerLauris BH <lauris@nix.lv>2019-03-02 15:07:19 +0200
commita5604b161100ca8723c016688f61003dc138316a (patch)
treec7751443cfb0b91484a7538a148e9639d96b4768 /models/repo.go
parentb28e527a2bc6bba034cbb9ed48b93d0422e09032 (diff)
downloadgitea-a5604b161100ca8723c016688f61003dc138316a.tar.gz
gitea-a5604b161100ca8723c016688f61003dc138316a.zip
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 <jeblair@redhat.com>
Diffstat (limited to 'models/repo.go')
-rw-r--r--models/repo.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/models/repo.go b/models/repo.go
index 848a76fe88..4d7320a789 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -1564,6 +1564,11 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error
}
}
+ // If there was previously a redirect at this location, remove it.
+ if err = deleteRepoRedirect(sess, newOwner.ID, repo.Name); err != nil {
+ return fmt.Errorf("delete repo redirect: %v", err)
+ }
+
return sess.Commit()
}
@@ -1614,7 +1619,18 @@ func ChangeRepositoryName(u *User, oldRepoName, newRepoName string) (err error)
RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath())
}
- return nil
+ sess := x.NewSession()
+ defer sess.Close()
+ if err = sess.Begin(); err != nil {
+ return fmt.Errorf("sess.Begin: %v", err)
+ }
+
+ // If there was previously a redirect at this location, remove it.
+ if err = deleteRepoRedirect(sess, u.ID, newRepoName); err != nil {
+ return fmt.Errorf("delete repo redirect: %v", err)
+ }
+
+ return sess.Commit()
}
func getRepositoriesByForkID(e Engine, forkID int64) ([]*Repository, error) {