From 03a32cda0ee772dfaeb8e684ebc68e0dda734243 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sun, 31 Jul 2022 20:29:55 +0200 Subject: [PATCH 1/2] Clean up and fix clone button script (#20415) The button 'primary' class needs to be set in a synchronous script to prevent flicker of the button which was regressed recently, fixed that. Additionally, reduced the two script tags to just one, the previous scripts were actually initializing the buttons thrice on the empty repo page, now it only initializes once. Finally, removed duplicate code and re-used the inline function in the update code as well. I had to split out the script into a separate template as on the empty repo page, the script needs access to the clone URL span in the example text, which is rendered below the clone buttons, so buttons and script could not be combined. --- templates/repo/clone_buttons.tmpl | 11 +---------- templates/repo/clone_script.tmpl | 23 +++++++++++++++++++++++ templates/repo/empty.tmpl | 19 +++---------------- templates/repo/home.tmpl | 1 + templates/repo/wiki/revision.tmpl | 1 + templates/repo/wiki/view.tmpl | 1 + web_src/js/features/repo-common.js | 30 +++--------------------------- 7 files changed, 33 insertions(+), 53 deletions(-) create mode 100644 templates/repo/clone_script.tmpl diff --git a/templates/repo/clone_buttons.tmpl b/templates/repo/clone_buttons.tmpl index 5affc5f322cae..0e6aae100a9b0 100644 --- a/templates/repo/clone_buttons.tmpl +++ b/templates/repo/clone_buttons.tmpl @@ -9,16 +9,7 @@ SSH {{end}} - - - + diff --git a/templates/repo/clone_script.tmpl b/templates/repo/clone_script.tmpl new file mode 100644 index 0000000000000..48b7ad3299ca2 --- /dev/null +++ b/templates/repo/clone_script.tmpl @@ -0,0 +1,23 @@ + diff --git a/templates/repo/empty.tmpl b/templates/repo/empty.tmpl index eee607ecafba7..af2ac2b920eea 100644 --- a/templates/repo/empty.tmpl +++ b/templates/repo/empty.tmpl @@ -37,7 +37,7 @@ git init {{if ne .Repository.DefaultBranch "master"}}git checkout -b {{.Repository.DefaultBranch}}{{end}} git add README.md git commit -m "first commit" -git remote add origin +git remote add origin git push -u origin {{.Repository.DefaultBranch}} @@ -46,24 +46,11 @@ git push -u origin {{.Repository.DefaultBranch}}

{{.i18n.Tr "repo.push_exist_repo"}}

-
git remote add origin 
+									
git remote add origin 
 git push -u origin {{.Repository.DefaultBranch}}
- - + {{template "repo/clone_script" .}} {{end}} {{else}}
diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 1a0323f5d1826..28cb9df6368f3 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -124,6 +124,7 @@ {{if eq $n 0}}
{{template "repo/clone_buttons" .}} + {{template "repo/clone_script" .}} {{end}} - + diff --git a/templates/repo/empty.tmpl b/templates/repo/empty.tmpl index af2ac2b920eea..7703cb661a61a 100644 --- a/templates/repo/empty.tmpl +++ b/templates/repo/empty.tmpl @@ -37,7 +37,7 @@ git init {{if ne .Repository.DefaultBranch "master"}}git checkout -b {{.Repository.DefaultBranch}}{{end}} git add README.md git commit -m "first commit" -git remote add origin +git remote add origin {{$.CloneButtonOriginLink.HTTPS}} git push -u origin {{.Repository.DefaultBranch}}
@@ -46,7 +46,7 @@ git push -u origin {{.Repository.DefaultBranch}}

{{.i18n.Tr "repo.push_exist_repo"}}

-
git remote add origin 
+									
git remote add origin {{$.CloneButtonOriginLink.HTTPS}}
 git push -u origin {{.Repository.DefaultBranch}}