fix(repo): stop advertising HTTP clone URLs when DISABLE_HTTP_GIT is set (#38378)

Fixes #38339

---------

Signed-off-by: TowyTowy <towy@airreps.link>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
TowyTowy
2026-07-17 05:17:28 +00:00
committed by GitHub
co-authored by wxiaoguang
parent bca44bd736
commit 8a3daef525
12 changed files with 115 additions and 115 deletions
-4
View File
@@ -9,10 +9,6 @@
<meta name="description" content="{{if .Repository}}{{.Repository.Name}}{{if .Repository.Description}} - {{.Repository.Description}}{{end}}{{else}}{{MetaDescription}}{{end}}">
<meta name="keywords" content="{{MetaKeywords}}">
<meta name="referrer" content="same-origin">{{/* required by: 1. "redirect_to" cookie; 2. cross-origin protection */}}
{{if .GoGetImport}}
<meta name="go-import" content="{{.GoGetImport}} git {{.RepoCloneLink.HTTPS}}">
<meta name="go-source" content="{{.GoGetImport}} _ {{.GoDocDirectory}} {{.GoDocFile}}">
{{end}}
{{if and .EnableFeed .FeedURL}}
<link rel="alternate" type="application/atom+xml" title="" href="{{.FeedURL}}.atom">
<link rel="alternate" type="application/rss+xml" title="" href="{{.FeedURL}}.rss">
+10 -7
View File
@@ -1,13 +1,16 @@
<!-- there is always at least one button (guaranteed by context/repo.go) -->
<div class="ui action small input clone-buttons-combo">
{{if $.CloneButtonShowHTTPS}}
<button class="ui small button repo-clone-https" data-link="{{$.CloneButtonOriginLink.HTTPS}}">HTTPS</button>
<!-- render the clone combo only when a git protocol is available; the URL input would otherwise be empty -->
{{$cloneLink := $.CloneButtonOriginLink}}
{{if or $cloneLink.SupportHTTPS $cloneLink.SupportSSH}}
<div class="ui action small input clone-buttons-combo" data-global-init="initRepoCloneButtonsCombo">
{{if $cloneLink.SupportHTTPS}}
<button class="ui small button repo-clone-https" data-link="{{$cloneLink.HTTPS}}">HTTPS</button>
{{end}}
{{if $.CloneButtonShowSSH}}
<button class="ui small button repo-clone-ssh" data-link="{{$.CloneButtonOriginLink.SSH}}">SSH</button>
{{if $cloneLink.SupportSSH}}
<button class="ui small button repo-clone-ssh" data-link="{{$cloneLink.SSH}}">SSH</button>
{{end}}
<input size="10" class="repo-clone-url js-clone-url" value="{{$.CloneButtonOriginLink.HTTPS}}" readonly>
<input size="10" class="repo-clone-url js-clone-url" value="{{Iif $cloneLink.SupportHTTPS $cloneLink.HTTPS $cloneLink.SSH}}" readonly>
<button class="ui small icon button" data-clipboard-target=".repo-clone-url" data-tooltip-content="{{ctx.Locale.Tr "copy_url"}}">
{{svg "octicon-copy" 14}}
</button>
</div>
{{end}}
+44 -36
View File
@@ -1,48 +1,56 @@
<button class="ui compact primary button js-btn-clone-panel">
{{$cloneLink := $.CloneButtonOriginLink}}
{{$downloadArchiveLinkPrefix := $.DownloadArchiveLinkPrefix}}
{{$openWithEditorApps := $.OpenWithEditorApps}}
{{$showCloneLinks := or $cloneLink.SupportHTTPS $cloneLink.SupportSSH}}
{{$showOpenWithEditorApps := and $showCloneLinks $openWithEditorApps}}{{/* the editor apps need the clone link */}}
{{if or $showCloneLinks $showOpenWithEditorApps $downloadArchiveLinkPrefix}}
<button class="ui compact primary button" data-global-init="initRepoClonePanel">
{{svg "octicon-code" 16}}
<span>{{ctx.Locale.Tr "repo.code"}}</span>
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
</button>
<div class="clone-panel-popup tippy-target">
<div class="flex-text-block clone-panel-field">{{svg "octicon-terminal"}} Clone</div>
<div class="clone-panel-tab">
<!-- there is always at least one button (guaranteed by context/repo.go) -->
{{if $.CloneButtonShowHTTPS}}
<button class="item repo-clone-https" data-link="{{$.CloneButtonOriginLink.HTTPS}}">HTTPS</button>
{{end}}
{{if $.CloneButtonShowSSH}}
<button class="item repo-clone-ssh" data-link="{{$.CloneButtonOriginLink.SSH}}">SSH</button>
{{end}}
<button class="item repo-clone-tea" data-link="{{$.CloneButtonOriginLink.Tea}}">Tea CLI</button>
</div>
<div class="divider"></div>
<div class="clone-panel-field">
<div class="ui input tiny action">
<input size="30" class="repo-clone-url js-clone-url" value="{{$.CloneButtonOriginLink.HTTPS}}" readonly>
<div class="ui small compact icon button" data-clipboard-target=".js-clone-url" data-tooltip-content="{{ctx.Locale.Tr "copy_url"}}">
{{svg "octicon-copy" 14}}
</div>
</div>
</div>
{{if not .PageIsWiki}}
<div class="flex-items-block clone-panel-list">
{{range .OpenWithEditorApps}}
<a class="item muted js-clone-url-editor" data-href-template="{{.OpenURL}}">{{.IconHTML}}{{ctx.Locale.Tr "repo.open_with_editor" .DisplayName}}</a>
{{if $showCloneLinks}}
<div class="flex-text-block clone-panel-field">{{svg "octicon-terminal"}} Clone</div>
<div class="clone-panel-tab">
<!-- tea clone also uses the git HTTPS/SSH transports, so the whole clone section is hidden when both are disabled -->
{{if $cloneLink.SupportHTTPS}}
<button class="item repo-clone-https" data-link="{{$cloneLink.HTTPS}}">HTTPS</button>
{{end}}
{{if $cloneLink.SupportSSH}}
<button class="item repo-clone-ssh" data-link="{{$cloneLink.SSH}}">SSH</button>
{{end}}
{{if not $cloneLink.IsWikiRepo}}
<button class="item repo-clone-tea" data-link="{{$cloneLink.Tea}}">Tea CLI</button>
{{end}}
</div>
{{if and (not $.DisableDownloadSourceArchives) $.RefFullName}}
<div class="divider"></div>
<div class="clone-panel-field">
<div class="ui input tiny action">
<input size="30" class="repo-clone-url js-clone-url" value="{{Iif $cloneLink.SupportHTTPS $cloneLink.HTTPS $cloneLink.SSH}}" readonly>
<div class="ui small compact icon button" data-clipboard-target=".js-clone-url" data-tooltip-content="{{ctx.Locale.Tr "copy_url"}}">
{{svg "octicon-copy" 14}}
</div>
</div>
</div>
{{end}}
{{if $showOpenWithEditorApps}}
<div class="flex-items-block clone-panel-list repo-clone-with-apps">
{{range $app := $openWithEditorApps}}
<a class="item muted js-clone-url-editor" data-href-template="{{$app.OpenURL}}">{{$app.IconHTML}}{{ctx.Locale.Tr "repo.open_with_editor" $app.DisplayName}}</a>
{{end}}
</div>
{{end}}
{{if $downloadArchiveLinkPrefix}}
{{if $showOpenWithEditorApps}}<div class="divider"></div>{{end}}
<div class="flex-items-block clone-panel-list">
{{/* FIXME: here it only uses the shortname in the ref to build the link, it can't distinguish the branch/tag/commit with the same name
in the future, it's better to use something like "/archive/branch/the-name.zip", "/archive/tag/the-name.zip" */}}
<a class="item muted archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.RefFullName.ShortName}}.zip" rel="nofollow">{{svg "octicon-file-zip"}} {{ctx.Locale.Tr "repo.download_zip"}}</a>
<a class="item muted archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.RefFullName.ShortName}}.tar.gz" rel="nofollow">{{svg "octicon-file-zip"}} {{ctx.Locale.Tr "repo.download_tar"}}</a>
<a class="item muted archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.RefFullName.ShortName}}.bundle" rel="nofollow">{{svg "octicon-package"}} {{ctx.Locale.Tr "repo.download_bundle"}}</a>
<a class="item muted archive-link" href="{{$downloadArchiveLinkPrefix}}.zip" rel="nofollow">{{svg "octicon-file-zip"}} {{ctx.Locale.Tr "repo.download_zip"}}</a>
<a class="item muted archive-link" href="{{$downloadArchiveLinkPrefix}}.tar.gz" rel="nofollow">{{svg "octicon-file-zip"}} {{ctx.Locale.Tr "repo.download_tar"}}</a>
<a class="item muted archive-link" href="{{$downloadArchiveLinkPrefix}}.bundle" rel="nofollow">{{svg "octicon-package"}} {{ctx.Locale.Tr "repo.download_bundle"}}</a>
</div>
{{end}}
{{end}}
</div>
{{end}}
+11 -8
View File
@@ -21,7 +21,7 @@
<div class="ui segment center">{{ctx.Locale.Tr "repo.no_branch"}}</div>
{{else if .CanWriteCode}}
<h4 class="ui top attached header">{{ctx.Locale.Tr "repo.quick_guide"}}</h4>
<div class="ui attached guide table segment empty-repo-guide">
<div class="ui attached segment empty-repo-guide flex-relaxed-list">
<div class="item">
<h3>{{ctx.Locale.Tr "repo.clone_this_repo"}} <small>{{ctx.Locale.Tr "repo.clone_helper" "http://git-scm.com/book/en/v2/Git-Basics-Getting-a-Git-Repository"}}</small></h3>
@@ -36,12 +36,15 @@
</a>
{{end}}
{{end}}
{{template "repo/clone_buttons" .}}
{{template "repo/clone_buttons" dict "CloneButtonOriginLink" $.CloneButtonOriginLink}}
</div>
</div>
{{if not .Repository.IsArchived}}
<div class="divider tw-my-0"></div>
{{$cloneLink := $.CloneButtonOriginLink}}
{{$showGitClientCommands := and (or $cloneLink.SupportHTTPS $cloneLink.SupportSSH) (not .Repository.IsArchived)}}
{{/* TODO: when both HTTPS and SSH are disabled, the UI is not that good */}}
{{if $showGitClientCommands}}
<div class="divider"></div>
<div class="item">
<h3>{{ctx.Locale.Tr "repo.create_new_repo_command"}}</h3>
@@ -52,19 +55,19 @@ git init{{if ne .Repository.ObjectFormatName "sha1"}} --object-format={{.Reposit
{{if ne .Repository.DefaultBranch "master"}}git checkout -b {{.Repository.DefaultBranch}}{{end}}
git add README.md
git commit -m "first commit"
git remote add {{$gitRemoteName}} <span class="js-clone-url">{{$.CloneButtonOriginLink.HTTPS}}</span>
git remote add {{$gitRemoteName}} <span class="js-clone-url">{{Iif $cloneLink.SupportHTTPS $cloneLink.HTTPS $cloneLink.SSH}}</span>
git push -u {{$gitRemoteName}} {{.Repository.DefaultBranch}}</code></pre>
</div>
</div>
<div class="divider"></div>
<div class="item">
<h3>{{ctx.Locale.Tr "repo.push_exist_repo"}}</h3>
<div class="markup">
<pre><code>git remote add {{$gitRemoteName}} <span class="js-clone-url">{{$.CloneButtonOriginLink.HTTPS}}</span>
<pre><code>git remote add {{$gitRemoteName}} <span class="js-clone-url">{{Iif $cloneLink.SupportHTTPS $cloneLink.HTTPS $cloneLink.SSH}}</span>
git push -u {{$gitRemoteName}} {{.Repository.DefaultBranch}}</code></pre>
</div>
</div>
{{else}}
<div class="item">HTTPS and SSH clones are disabled, you can only modify the repository via Gitea's web UI.</div>
{{end}}
</div>
{{else}}
+5 -1
View File
@@ -112,7 +112,11 @@
{{end}}
<!-- Only show clone panel in repository home page -->
{{if $isTreePathRoot}}
{{template "repo/clone_panel" .}}
{{template "repo/clone_panel" (dict
"CloneButtonOriginLink" $.CloneButtonOriginLink
"OpenWithEditorApps" $.OpenWithEditorApps
"DownloadArchiveLinkPrefix" $.DownloadArchiveLinkPrefix
)}}
{{end}}
{{if and (not $isTreePathRoot) (not .IsViewFile) (not .IsBlame)}}{{/* IsViewDirectory (not home), TODO: split the templates, avoid using "if" tricks */}}
<a class="ui compact button" href="{{.RepoLink}}/commits/{{.RefTypeNameSubURL}}/{{.TreePath | PathEscapeSegments}}">
+1 -1
View File
@@ -15,7 +15,7 @@
</div>
</div>
<div class="flex-text-block">
{{template "repo/clone_panel" .}}
{{template "repo/clone_panel" dict "CloneButtonOriginLink" $.CloneButtonOriginLink}}
</div>
</div>
<h2 class="ui top header">{{ctx.Locale.Tr "repo.wiki.wiki_page_revisions"}}</h2>
+1 -1
View File
@@ -28,7 +28,7 @@
</div>
</div>
</div>
{{template "repo/clone_panel" .}}
{{template "repo/clone_panel" dict "CloneButtonOriginLink" $.CloneButtonOriginLink}}
</div>
<div class="ui dividing header">
<div class="flex-text-block tw-flex-wrap tw-justify-end">