From 961956b800099f9272dc151700c82a166d37c7e2 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 9 Jan 2025 07:36:09 +0000 Subject: [PATCH 1/7] fix --- templates/repo/commit_page.tmpl | 2 +- templates/repo/commits.tmpl | 2 +- templates/repo/home.tmpl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/repo/commit_page.tmpl b/templates/repo/commit_page.tmpl index bc63db9b62713..4b48ecb7bde12 100644 --- a/templates/repo/commit_page.tmpl +++ b/templates/repo/commit_page.tmpl @@ -60,7 +60,7 @@ "Repository" .Repository "ShowTabBranches" true "CurrentRefType" "branch" - "CurrentRefShortName" (or $.BranchName $.Repository.DefaultBranch) + "CurrentRefShortName" (or $.RefName $.Repository.DefaultBranch) "RefFormActionTemplate" (print "{RepoLink}/_cherrypick/" .CommitID "/{RefShortName}") }}
diff --git a/templates/repo/commits.tmpl b/templates/repo/commits.tmpl index 7065bf33f4db1..8bebbdb7f1753 100644 --- a/templates/repo/commits.tmpl +++ b/templates/repo/commits.tmpl @@ -7,7 +7,7 @@
{{$branchDropdownCurrentRefType := "branch"}} - {{$branchDropdownCurrentRefShortName := .BranchName}} + {{$branchDropdownCurrentRefShortName := .RefName}} {{if .IsViewTag}} {{$branchDropdownCurrentRefType = "tag"}} {{$branchDropdownCurrentRefShortName = .TagName}} diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index d73b7470bc5cd..6ef7d3ea851bf 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -25,7 +25,7 @@
{{$branchDropdownCurrentRefType := "branch"}} - {{$branchDropdownCurrentRefShortName := .BranchName}} + {{$branchDropdownCurrentRefShortName := .RefName}} {{if .IsViewTag}} {{$branchDropdownCurrentRefType = "tag"}} {{$branchDropdownCurrentRefShortName = .TagName}} From ba52a6602cd00d5e13387e1a25ec06ebcd0fc5fa Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 9 Jan 2025 08:21:53 +0000 Subject: [PATCH 2/7] revert change in commit_page --- templates/repo/commit_page.tmpl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/templates/repo/commit_page.tmpl b/templates/repo/commit_page.tmpl index 4b48ecb7bde12..ef96f46812eed 100644 --- a/templates/repo/commit_page.tmpl +++ b/templates/repo/commit_page.tmpl @@ -52,7 +52,6 @@

-
{{/*FIXME: CurrentRefShortName seems not making sense here (old code), because the "commit page" has no "$.BranchName" info, so only using DefaultBranch should be enough */}} @@ -60,7 +59,7 @@ "Repository" .Repository "ShowTabBranches" true "CurrentRefType" "branch" - "CurrentRefShortName" (or $.RefName $.Repository.DefaultBranch) + "CurrentRefShortName" (or $.BranchName $.Repository.DefaultBranch) "RefFormActionTemplate" (print "{RepoLink}/_cherrypick/" .CommitID "/{RefShortName}") }}
From ed7066eb209abd76f7b91ca1d39eda690c08a60e Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 9 Jan 2025 08:40:54 +0000 Subject: [PATCH 3/7] convert to ShortSha --- templates/repo/commits.tmpl | 3 +++ templates/repo/home.tmpl | 3 +++ 2 files changed, 6 insertions(+) diff --git a/templates/repo/commits.tmpl b/templates/repo/commits.tmpl index 8bebbdb7f1753..c51f40588a3d8 100644 --- a/templates/repo/commits.tmpl +++ b/templates/repo/commits.tmpl @@ -8,6 +8,9 @@ {{$branchDropdownCurrentRefType := "branch"}} {{$branchDropdownCurrentRefShortName := .RefName}} + {{if and (not .IsViewBranch) (not .IsViewTag)}} + {{$branchDropdownCurrentRefShortName = ShortSha .RefName}} + {{end}} {{if .IsViewTag}} {{$branchDropdownCurrentRefType = "tag"}} {{$branchDropdownCurrentRefShortName = .TagName}} diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 6ef7d3ea851bf..7f1e65a585f61 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -26,6 +26,9 @@
{{$branchDropdownCurrentRefType := "branch"}} {{$branchDropdownCurrentRefShortName := .RefName}} + {{if and (not .IsViewBranch) (not .IsViewTag)}} + {{$branchDropdownCurrentRefShortName = ShortSha .RefName}} + {{end}} {{if .IsViewTag}} {{$branchDropdownCurrentRefType = "tag"}} {{$branchDropdownCurrentRefShortName = .TagName}} From 8eacb3d9631183250c06f36843b289d73a271ede Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 9 Jan 2025 08:43:32 +0000 Subject: [PATCH 4/7] simplify --- templates/repo/commits.tmpl | 5 ++--- templates/repo/home.tmpl | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/templates/repo/commits.tmpl b/templates/repo/commits.tmpl index c51f40588a3d8..8512cd2e09d40 100644 --- a/templates/repo/commits.tmpl +++ b/templates/repo/commits.tmpl @@ -8,12 +8,11 @@ {{$branchDropdownCurrentRefType := "branch"}} {{$branchDropdownCurrentRefShortName := .RefName}} - {{if and (not .IsViewBranch) (not .IsViewTag)}} - {{$branchDropdownCurrentRefShortName = ShortSha .RefName}} - {{end}} {{if .IsViewTag}} {{$branchDropdownCurrentRefType = "tag"}} {{$branchDropdownCurrentRefShortName = .TagName}} + {{else if not .IsViewBranch}} + {{$branchDropdownCurrentRefShortName = ShortSha .RefName}} {{end}} {{template "repo/branch_dropdown" dict "Repository" .Repository diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 7f1e65a585f61..792b0d91558e3 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -26,12 +26,11 @@
{{$branchDropdownCurrentRefType := "branch"}} {{$branchDropdownCurrentRefShortName := .RefName}} - {{if and (not .IsViewBranch) (not .IsViewTag)}} - {{$branchDropdownCurrentRefShortName = ShortSha .RefName}} - {{end}} {{if .IsViewTag}} {{$branchDropdownCurrentRefType = "tag"}} {{$branchDropdownCurrentRefShortName = .TagName}} + {{else if not .IsViewBranch}} + {{$branchDropdownCurrentRefShortName = ShortSha .RefName}} {{end}} {{template "repo/branch_dropdown" dict "Repository" .Repository From 7706924c17a93f6a89e7548286c9c7e795159f69 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 9 Jan 2025 08:44:23 +0000 Subject: [PATCH 5/7] remove unnecessary change --- templates/repo/commit_page.tmpl | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/repo/commit_page.tmpl b/templates/repo/commit_page.tmpl index ef96f46812eed..bc63db9b62713 100644 --- a/templates/repo/commit_page.tmpl +++ b/templates/repo/commit_page.tmpl @@ -52,6 +52,7 @@

+ {{/*FIXME: CurrentRefShortName seems not making sense here (old code), because the "commit page" has no "$.BranchName" info, so only using DefaultBranch should be enough */}} From 90b5aef3e3cc9d7b8748e2e993b28ac7728646c8 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 9 Jan 2025 18:27:09 +0800 Subject: [PATCH 6/7] fix --- templates/repo/commits.tmpl | 26 ++++++++++++++------------ templates/repo/home.tmpl | 24 ++++++++++++++---------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/templates/repo/commits.tmpl b/templates/repo/commits.tmpl index 8512cd2e09d40..d80d4ac276474 100644 --- a/templates/repo/commits.tmpl +++ b/templates/repo/commits.tmpl @@ -5,16 +5,19 @@ {{template "repo/sub_menu" .}}
- - {{$branchDropdownCurrentRefType := "branch"}} - {{$branchDropdownCurrentRefShortName := .RefName}} - {{if .IsViewTag}} - {{$branchDropdownCurrentRefType = "tag"}} - {{$branchDropdownCurrentRefShortName = .TagName}} - {{else if not .IsViewBranch}} - {{$branchDropdownCurrentRefShortName = ShortSha .RefName}} - {{end}} - {{template "repo/branch_dropdown" dict + {{- /* for /owner/repo/commits/branch/the-name */ -}} + {{- $branchDropdownCurrentRefType := "branch" -}} + {{- $branchDropdownCurrentRefShortName := .BranchName -}} + {{- if .IsViewTag -}} + {{- /* for /owner/repo/commits/tag/the-name */ -}} + {{- $branchDropdownCurrentRefType = "tag" -}} + {{- $branchDropdownCurrentRefShortName = .TagName -}} + {{- else if .IsViewCommit -}} + {{- /* for /owner/repo/commits/commit/000000 */ -}} + {{- $branchDropdownCurrentRefType = "commit" -}} + {{- $branchDropdownCurrentRefShortName = ShortSha .CommitID -}} + {{- end -}} + {{- template "repo/branch_dropdown" dict "Repository" .Repository "ShowTabBranches" true "ShowTabTags" true @@ -23,8 +26,7 @@ "CurrentTreePath" .TreePath "RefLinkTemplate" "{RepoLink}/commits/{RefType}/{RefShortName}/{TreePath}" "AllowCreateNewRef" .CanCreateBranch - }} - + -}} {{svg "octicon-git-branch"}} {{ctx.Locale.Tr "repo.commit_graph"}} diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 792b0d91558e3..f80c9c1f4b37d 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -24,15 +24,19 @@ {{template "repo/sub_menu" .}}
- {{$branchDropdownCurrentRefType := "branch"}} - {{$branchDropdownCurrentRefShortName := .RefName}} - {{if .IsViewTag}} - {{$branchDropdownCurrentRefType = "tag"}} - {{$branchDropdownCurrentRefShortName = .TagName}} - {{else if not .IsViewBranch}} - {{$branchDropdownCurrentRefShortName = ShortSha .RefName}} - {{end}} - {{template "repo/branch_dropdown" dict + {{- /* for repo home (default branch) and /owner/repo/src/branch/the-name */ -}} + {{- $branchDropdownCurrentRefType := "branch" -}} + {{- $branchDropdownCurrentRefShortName := .BranchName -}} + {{- if .IsViewTag -}} + {{- /* for /owner/repo/src/tag/the-name */ -}} + {{- $branchDropdownCurrentRefType = "tag" -}} + {{- $branchDropdownCurrentRefShortName = .TagName -}} + {{- else if .IsViewCommit -}} + {{- /* for /owner/repo/src/commit/000000 */ -}} + {{- $branchDropdownCurrentRefType = "commit" -}} + {{- $branchDropdownCurrentRefShortName = ShortSha .CommitID -}} + {{- end -}} + {{- template "repo/branch_dropdown" dict "Repository" .Repository "ShowTabBranches" true "ShowTabTags" true @@ -42,7 +46,7 @@ "RefLinkTemplate" "{RepoLink}/src/{RefType}/{RefShortName}/{TreePath}" "AllowCreateNewRef" .CanCreateBranch "ShowViewAllRefsEntry" true - }} + -}} {{if and .CanCompareOrPull .IsViewBranch (not .Repository.IsArchived)}} {{$cmpBranch := ""}} {{if ne .Repository.ID .BaseRepo.ID}} From 612201a2e166ec77044b8f69a62f62e6418a0fbd Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 9 Jan 2025 11:48:30 +0000 Subject: [PATCH 7/7] add description about "commit" type --- templates/repo/branch_dropdown.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/repo/branch_dropdown.tmpl b/templates/repo/branch_dropdown.tmpl index b68c34a02af0a..6efed3427f44d 100644 --- a/templates/repo/branch_dropdown.tmpl +++ b/templates/repo/branch_dropdown.tmpl @@ -1,8 +1,8 @@ {{/* Attributes: * ContainerClasses * Repository -* CurrentRefType: eg. "branch", "tag" -* CurrentRefShortName: eg. "master", "v1.0" +* CurrentRefType: eg. "branch", "tag", "commit" +* CurrentRefShortName: eg. "master", "v1.0", "abcdef0123" * CurrentTreePath * RefLinkTemplate: redirect to the link when a branch/tag is selected * RefFormActionTemplate: change the parent form's action when a branch/tag is selected