summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/repo/repo.go16
-rw-r--r--models/repo/update.go4
-rw-r--r--models/repo_transfer.go4
3 files changed, 14 insertions, 10 deletions
diff --git a/models/repo/repo.go b/models/repo/repo.go
index f9de6d493d..2e8c28cbb3 100644
--- a/models/repo/repo.go
+++ b/models/repo/repo.go
@@ -726,12 +726,9 @@ func GetRepositoriesMapByIDs(ids []int64) (map[int64]*Repository, error) {
return repos, db.GetEngine(db.DefaultContext).In("id", ids).Find(&repos)
}
-// IsRepositoryExist returns true if the repository with given name under user has already existed.
-func IsRepositoryExist(ctx context.Context, u *user_model.User, repoName string) (bool, error) {
- has, err := db.GetEngine(ctx).Get(&Repository{
- OwnerID: u.ID,
- LowerName: strings.ToLower(repoName),
- })
+// IsRepositoryModelOrDirExist returns true if the repository with given name under user has already existed.
+func IsRepositoryModelOrDirExist(ctx context.Context, u *user_model.User, repoName string) (bool, error) {
+ has, err := IsRepositoryModelExist(ctx, u, repoName)
if err != nil {
return false, err
}
@@ -739,6 +736,13 @@ func IsRepositoryExist(ctx context.Context, u *user_model.User, repoName string)
return has || isDir, err
}
+func IsRepositoryModelExist(ctx context.Context, u *user_model.User, repoName string) (bool, error) {
+ return db.GetEngine(ctx).Get(&Repository{
+ OwnerID: u.ID,
+ LowerName: strings.ToLower(repoName),
+ })
+}
+
// GetTemplateRepo populates repo.TemplateRepo for a generated repository and
// returns an error on failure (NOTE: no error is returned for
// non-generated repositories, and TemplateRepo will be left untouched)
diff --git a/models/repo/update.go b/models/repo/update.go
index f4cb67bb8f..4894e0a1b9 100644
--- a/models/repo/update.go
+++ b/models/repo/update.go
@@ -116,7 +116,7 @@ func CheckCreateRepository(doer, u *user_model.User, name string, overwriteOrAdo
return err
}
- has, err := IsRepositoryExist(db.DefaultContext, u, name)
+ has, err := IsRepositoryModelOrDirExist(db.DefaultContext, u, name)
if err != nil {
return fmt.Errorf("IsRepositoryExist: %w", err)
} else if has {
@@ -147,7 +147,7 @@ func ChangeRepositoryName(doer *user_model.User, repo *Repository, newRepoName s
return err
}
- has, err := IsRepositoryExist(db.DefaultContext, repo.Owner, newRepoName)
+ has, err := IsRepositoryModelOrDirExist(db.DefaultContext, repo.Owner, newRepoName)
if err != nil {
return fmt.Errorf("IsRepositoryExist: %w", err)
} else if has {
diff --git a/models/repo_transfer.go b/models/repo_transfer.go
index 27a77f9b8c..1c873cec57 100644
--- a/models/repo_transfer.go
+++ b/models/repo_transfer.go
@@ -172,7 +172,7 @@ func CreatePendingRepositoryTransfer(ctx context.Context, doer, newOwner *user_m
}
// Check if new owner has repository with same name.
- if has, err := repo_model.IsRepositoryExist(ctx, newOwner, repo.Name); err != nil {
+ if has, err := repo_model.IsRepositoryModelExist(ctx, newOwner, repo.Name); err != nil {
return fmt.Errorf("IsRepositoryExist: %w", err)
} else if has {
return repo_model.ErrRepoAlreadyExist{
@@ -249,7 +249,7 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo
newOwnerName = newOwner.Name // ensure capitalisation matches
// Check if new owner has repository with same name.
- if has, err := repo_model.IsRepositoryExist(ctx, newOwner, repo.Name); err != nil {
+ if has, err := repo_model.IsRepositoryModelOrDirExist(ctx, newOwner, repo.Name); err != nil {
return fmt.Errorf("IsRepositoryExist: %w", err)
} else if has {
return repo_model.ErrRepoAlreadyExist{