From 5236d8a93675b18e4dfb20ff567bc39c2ea91f40 Mon Sep 17 00:00:00 2001 From: Segev Finer Date: Tue, 16 Apr 2019 22:47:09 +0300 Subject: [PATCH] Fix forking an empty repository (#6637) (#6653) Fixes #6633 Signed-off-by: Segev Finer --- models/repo.go | 1 + modules/context/repo.go | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/models/repo.go b/models/repo.go index 3a887c6c3..92937e927 100644 --- a/models/repo.go +++ b/models/repo.go @@ -2432,6 +2432,7 @@ func ForkRepository(doer, u *User, oldRepo *Repository, name, desc string) (_ *R Description: desc, DefaultBranch: oldRepo.DefaultBranch, IsPrivate: oldRepo.IsPrivate, + IsEmpty: oldRepo.IsEmpty, IsFork: true, ForkID: oldRepo.ID, } diff --git a/modules/context/repo.go b/modules/context/repo.go index e0ee802f7..5a3028c4d 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -396,6 +396,13 @@ func RepoAssignment() macaron.Handler { ctx.Data["IsStaringRepo"] = models.IsStaring(ctx.User.ID, repo.ID) } + if repo.IsFork { + RetrieveBaseRepo(ctx, repo) + if ctx.Written() { + return + } + } + // repo is empty and display enable if ctx.Repo.Repository.IsEmpty { ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch @@ -423,13 +430,6 @@ func RepoAssignment() macaron.Handler { ctx.Data["BranchName"] = ctx.Repo.BranchName ctx.Data["CommitID"] = ctx.Repo.CommitID - if repo.IsFork { - RetrieveBaseRepo(ctx, repo) - if ctx.Written() { - return - } - } - // People who have push access or have forked repository can propose a new pull request. if ctx.Repo.CanWrite(models.UnitTypeCode) || (ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID)) { // Pull request is allowed if this is a fork repository