From cc8da0cd99829c1d5811acef282e28b5f92eeba4 Mon Sep 17 00:00:00 2001 From: Mario Lubenka Date: Wed, 18 Dec 2019 20:53:28 +0100 Subject: [PATCH 1/2] Push update after branch is restored Signed-off-by: Mario Lubenka --- routers/repo/branch.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/routers/repo/branch.go b/routers/repo/branch.go index 306deca36e653..39583ceb6bda7 100644 --- a/routers/repo/branch.go +++ b/routers/repo/branch.go @@ -110,6 +110,22 @@ func RestoreBranchPost(ctx *context.Context) { return } + // Don't return error below this + if err := repofiles.PushUpdate( + ctx.Repo.Repository, + branchName, + repofiles.PushUpdateOptions{ + RefFullName: git.BranchPrefix + branchName, + OldCommitID: git.EmptySHA, + NewCommitID: deletedBranch.Commit, + PusherID: ctx.User.ID, + PusherName: ctx.User.Name, + RepoUserName: ctx.Repo.Owner.Name, + RepoName: ctx.Repo.Repository.Name, + }); err != nil { + log.Error("Update: %v", err) + } + ctx.Flash.Success(ctx.Tr("repo.branch.restore_success", deletedBranch.Name)) } From 0fdec0c083fbdc7f21946de41e8e6a5d0a77dd5d Mon Sep 17 00:00:00 2001 From: Mario Lubenka Date: Mon, 23 Dec 2019 16:36:27 +0100 Subject: [PATCH 2/2] Apply suggestions from code review Use name from deletedBranch --- routers/repo/branch.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routers/repo/branch.go b/routers/repo/branch.go index 39583ceb6bda7..b0a1efc5b92b5 100644 --- a/routers/repo/branch.go +++ b/routers/repo/branch.go @@ -113,9 +113,9 @@ func RestoreBranchPost(ctx *context.Context) { // Don't return error below this if err := repofiles.PushUpdate( ctx.Repo.Repository, - branchName, + deletedBranch.Name, repofiles.PushUpdateOptions{ - RefFullName: git.BranchPrefix + branchName, + RefFullName: git.BranchPrefix + deletedBranch.Name, OldCommitID: git.EmptySHA, NewCommitID: deletedBranch.Commit, PusherID: ctx.User.ID,