Преглед на файлове

repo/setting: filter out deleted branch in protect list (#4288)

Unknwon преди 8 години
родител
ревизия
7c802f6d83
променени са 2 файла, в които са добавени 10 реда и са изтрити 2 реда
  1. 9 1
      routers/repo/setting.go
  2. 1 1
      templates/repo/settings/branches.tmpl

+ 9 - 1
routers/repo/setting.go

@@ -373,7 +373,15 @@ func SettingsBranches(ctx *context.Context) {
 		ctx.Handle(500, "GetProtectBranchesByRepoID", err)
 		return
 	}
-	ctx.Data["ProtectBranches"] = protectBranches
+
+	// Filter out deleted branches
+	branches := make([]string, 0, len(protectBranches))
+	for i := range protectBranches {
+		if ctx.Repo.GitRepo.IsBranchExist(protectBranches[i].Name) {
+			branches = append(branches, protectBranches[i].Name)
+		}
+	}
+	ctx.Data["ProtectBranches"] = branches
 
 	ctx.HTML(200, SETTINGS_BRANCHES)
 }

+ 1 - 1
templates/repo/settings/branches.tmpl

@@ -50,7 +50,7 @@
 					<div class="ui protected-branches list">
 						{{range .ProtectBranches}}
 							<div class="item">
-								<a href="{{$.Link}}/{{.Name}}"><code>{{.Name}}</code></a>
+								<a href="{{$.Link}}/{{.}}"><code>{{.}}</code></a>
 							</div>
 						{{end}}
 					</div>