From 709a376c518d0cfde10bb911b32fd0ea82c67b52 Mon Sep 17 00:00:00 2001
From: JakobDev <jakobdev@gmx.de>
Date: Mon, 27 Nov 2023 06:59:56 +0100
Subject: [PATCH] Fix link to `Code` tab on wiki commits (#28041)

Fixes https://codeberg.org/forgejo/forgejo/issues/1759

If you are bowing another branch than the default branch and click n the
Code tab, it will take you to the root of the branch. The `BranchName`
variable is also set when viewing a Wiki commit, so we also need to
check if we are on a Wiki.
---
 templates/repo/header.tmpl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl
index 895d18d6fd..f306435409 100644
--- a/templates/repo/header.tmpl
+++ b/templates/repo/header.tmpl
@@ -142,7 +142,7 @@
 		{{if not (or .Repository.IsBeingCreated .Repository.IsBroken)}}
 			<div class="ui tabular menu navbar gt-overflow-x-auto gt-overflow-y-hidden">
 				{{if .Permission.CanRead $.UnitTypeCode}}
-				<a class="{{if .PageIsViewCode}}active {{end}}item" href="{{.RepoLink}}{{if (ne .BranchName .Repository.DefaultBranch)}}/src/{{.BranchNameSubURL}}{{end}}">
+				<a class="{{if .PageIsViewCode}}active {{end}}item" href="{{.RepoLink}}{{if and (ne .BranchName .Repository.DefaultBranch) (not $.PageIsWiki)}}/src/{{.BranchNameSubURL}}{{end}}">
 					{{svg "octicon-code"}} {{ctx.Locale.Tr "repo.code"}}
 				</a>
 				{{end}}