From df9b6d25b84b3b8822b6f61288786443e8443860 Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Thu, 4 May 2023 11:39:28 +0800 Subject: [PATCH 1/9] display warning if user try to rename default branch --- options/locale/locale_en-US.ini | 1 + templates/repo/branch/list.tmpl | 5 +++++ web_src/js/features/repo-branch.js | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 180fd1c18d0e9..226a53257348d 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2411,6 +2411,7 @@ branch.included_desc = This branch is part of the default branch branch.included = Included branch.create_new_branch = Create branch from branch: branch.confirm_create_branch = Create branch +branch.warning_raname_default_branch = You are trying to rename default branch. branch.rename_branch_to = Rename "%s" to: branch.confirm_rename_branch = Rename branch branch.create_branch_operation = Create branch diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl index 53ca2b9b09e1f..b20d37b8f09bc 100644 --- a/templates/repo/branch/list.tmpl +++ b/templates/repo/branch/list.tmpl @@ -55,6 +55,7 @@ data-modal="#rename-branch-modal" data-old-branch-name="{{$.DefaultBranch}}" data-tooltip-content="{{$.locale.Tr "repo.branch.rename" ($.DefaultBranch)}}" + data-is-defualt-branch="true" > {{svg "octicon-pencil"}} @@ -161,6 +162,7 @@ data-old-branch-name="{{.Name}}" data-modal="#rename-branch-modal" data-tooltip-content="{{$.locale.Tr "repo.branch.rename" (.Name)}}" + data-is-defualt-branch="false" > {{svg "octicon-pencil"}} @@ -229,6 +231,9 @@
{{.CsrfTokenHtml}} +
+ {{.locale.Tr "repo.branch.warning_raname_default_branch"}} +
diff --git a/web_src/js/features/repo-branch.js b/web_src/js/features/repo-branch.js index e7c2645dcd8af..77344f3449643 100644 --- a/web_src/js/features/repo-branch.js +++ b/web_src/js/features/repo-branch.js @@ -31,6 +31,11 @@ function initRepoRenameBranchButton() { const oldBranchName = $(this).attr('data-old-branch-name'); $modal.find('input[name=from]').val(oldBranchName); + // display the warning that the branch which is choosen is the default branch + const $warn = $modal.find('.default-branch-warning'); + if ($(this).attr('data-is-defualt-branch') !== 'true') $warn.addClass('gt-hidden'); + else $warn.removeClass('gt-hidden'); + const $text = $modal.find('[data-rename-branch-to]'); $text.text($text.attr('data-rename-branch-to').replace('%s', oldBranchName)); }); From 56f25c1e2cf777446ed4138f97c842209a7c0dea Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Thu, 4 May 2023 11:45:58 +0800 Subject: [PATCH 2/9] update --- templates/repo/branch/list.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl index b20d37b8f09bc..0178c2ae0178d 100644 --- a/templates/repo/branch/list.tmpl +++ b/templates/repo/branch/list.tmpl @@ -52,10 +52,10 @@ {{end}} {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not $.IsMirror)}} @@ -159,10 +159,10 @@ {{end}} {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not $.IsMirror)}} From bc724ca9691d1a5b466d6aac57cef2c7d3ea9e5b Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Thu, 4 May 2023 00:14:53 -0400 Subject: [PATCH 3/9] Apply suggestions from code review --- web_src/js/features/repo-branch.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web_src/js/features/repo-branch.js b/web_src/js/features/repo-branch.js index 77344f3449643..5f14ebeb675f5 100644 --- a/web_src/js/features/repo-branch.js +++ b/web_src/js/features/repo-branch.js @@ -31,9 +31,9 @@ function initRepoRenameBranchButton() { const oldBranchName = $(this).attr('data-old-branch-name'); $modal.find('input[name=from]').val(oldBranchName); - // display the warning that the branch which is choosen is the default branch + // display the warning that the branch which is chosen is the default branch const $warn = $modal.find('.default-branch-warning'); - if ($(this).attr('data-is-defualt-branch') !== 'true') $warn.addClass('gt-hidden'); + if ($(this).attr('data-is-default-branch') !== 'true') $warn.addClass('gt-hidden'); else $warn.removeClass('gt-hidden'); const $text = $modal.find('[data-rename-branch-to]'); From 2e2071f901c17e402451c71b45969337e6c2b4df Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Thu, 4 May 2023 12:18:38 +0800 Subject: [PATCH 4/9] typo --- templates/repo/branch/list.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl index 0178c2ae0178d..cad4a9581824b 100644 --- a/templates/repo/branch/list.tmpl +++ b/templates/repo/branch/list.tmpl @@ -52,7 +52,7 @@ {{end}} {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not $.IsMirror)}}