aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-09-14 18:07:08 +0100
committerGitHub <noreply@github.com>2021-09-14 18:07:08 +0100
commit0a542dd59f8061797976f33690bf10357aa0b0ad (patch)
treea74494a0e8120e4bfd32583e152ef466641de17b /modules
parent26ef180f466046f9cfab87eea5ea93f5d6da6998 (diff)
downloadgitea-0a542dd59f8061797976f33690bf10357aa0b0ad.tar.gz
gitea-0a542dd59f8061797976f33690bf10357aa0b0ad.zip
Decrement Fork Num when converting from Fork (#17035)
When converting repositories from forks to normal the root NumFork needs to be decremented too. Fix #17026 Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules')
-rw-r--r--modules/repository/fork.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/modules/repository/fork.go b/modules/repository/fork.go
index 4e750dec08..b154cc5ccd 100644
--- a/modules/repository/fork.go
+++ b/modules/repository/fork.go
@@ -132,3 +132,34 @@ func ForkRepository(doer, owner *models.User, opts models.ForkRepoOptions) (_ *m
return repo, nil
}
+
+// ConvertForkToNormalRepository convert the provided repo from a forked repo to normal repo
+func ConvertForkToNormalRepository(repo *models.Repository) error {
+ err := models.WithTx(func(ctx models.DBContext) error {
+ repo, err := models.GetRepositoryByIDCtx(ctx, repo.ID)
+ if err != nil {
+ return err
+ }
+
+ if !repo.IsFork {
+ return nil
+ }
+
+ if err := models.DecrementRepoForkNum(ctx, repo.ForkID); err != nil {
+ log.Error("Unable to decrement repo fork num for old root repo %d of repository %-v whilst converting from fork. Error: %v", repo.ForkID, repo, err)
+ return err
+ }
+
+ repo.IsFork = false
+ repo.ForkID = 0
+
+ if err := models.UpdateRepositoryCtx(ctx, repo, false); err != nil {
+ log.Error("Unable to update repository %-v whilst converting from fork. Error: %v", repo, err)
+ return err
+ }
+
+ return nil
+ })
+
+ return err
+}