From f2f99a7d0c7ea3c667d254062d648ec387e3ea09 Mon Sep 17 00:00:00 2001
From: zeripath <art27@cantab.net>
Date: Fri, 11 Dec 2020 17:27:00 +0000
Subject: [PATCH] Ensure that pusher is not nil preventing panic in push
 (#13945)

PR #13381 refactored notification actions to call NotifyCreateRef and
NotifyDeleteRef in a slightly different manner. This leads to the pusher
not being set before the call.

This PR ensures that the pusher is updated before the call.

Fix #13940

Signed-off-by: Andrew Thornton <art27@cantab.net>
---
 services/repository/push.go | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/services/repository/push.go b/services/repository/push.go
index 2e7f1a1521..4ac37c9703 100644
--- a/services/repository/push.go
+++ b/services/repository/push.go
@@ -97,6 +97,12 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
 		}
 		var commits = &repo_module.PushCommits{}
 		if opts.IsTag() { // If is tag reference {
+			if pusher == nil || pusher.ID != opts.PusherID {
+				var err error
+				if pusher, err = models.GetUserByID(opts.PusherID); err != nil {
+					return err
+				}
+			}
 			tagName := opts.TagName()
 			if opts.IsDelRef() {
 				delTags = append(delTags, tagName)