Skip to content

Commit 0c65711

Browse files
sillyguodongtechknowlogickwolfogresilverwindGiteaBot
authored
Display warning when user try to rename default branch (#24512)
Follow #24380 It's better to warn users when they try to rename the default branch. ![image](https://user-images.githubusercontent.com/33891828/236107929-c8ac2854-dd0f-4500-a0a7-800c8fe48861.png) --------- Co-authored-by: techknowlogick <[email protected]> Co-authored-by: Jason Song <[email protected]> Co-authored-by: silverwind <[email protected]> Co-authored-by: Giteabot <[email protected]>
1 parent 0ca1958 commit 0c65711

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,6 +2412,7 @@ branch.included_desc = This branch is part of the default branch
24122412
branch.included = Included
24132413
branch.create_new_branch = Create branch from branch:
24142414
branch.confirm_create_branch = Create branch
2415+
branch.warning_rename_default_branch = You are renaming the default branch.
24152416
branch.rename_branch_to = Rename "%s" to:
24162417
branch.confirm_rename_branch = Rename branch
24172418
branch.create_branch_operation = Create branch

templates/repo/branch/list.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
{{end}}
5353
{{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not $.IsMirror)}}
5454
<button class="ui tertiary button show-modal show-rename-branch-modal gt-mx-3"
55+
data-is-default-branch="true"
5556
data-modal="#rename-branch-modal"
5657
data-old-branch-name="{{$.DefaultBranch}}"
5758
data-tooltip-content="{{$.locale.Tr "repo.branch.rename" ($.DefaultBranch)}}"
@@ -158,6 +159,7 @@
158159
{{end}}
159160
{{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not $.IsMirror)}}
160161
<button class="ui tertiary button show-modal show-rename-branch-modal gt-mx-3"
162+
data-is-default-branch="false"
161163
data-old-branch-name="{{.Name}}"
162164
data-modal="#rename-branch-modal"
163165
data-tooltip-content="{{$.locale.Tr "repo.branch.rename" (.Name)}}"
@@ -229,6 +231,9 @@
229231
<form class="ui form" action="{{$.Repository.Link}}/settings/rename_branch" method="post">
230232
<div class="content">
231233
{{.CsrfTokenHtml}}
234+
<div class="field default-branch-warning">
235+
<span class="text red">{{.locale.Tr "repo.branch.warning_raname_default_branch"}}</span>
236+
</div>
232237
<div class="field">
233238
<span class="text" data-rename-branch-to="{{.locale.Tr "repo.branch.rename_branch_to"}}"></span>
234239
</div>

web_src/js/features/repo-branch.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import $ from 'jquery';
2+
import {toggleElem} from '../utils/dom.js';
23

34
export function initRepoBranchButton() {
45
initRepoCreateBranchButton();
@@ -31,6 +32,10 @@ function initRepoRenameBranchButton() {
3132
const oldBranchName = $(this).attr('data-old-branch-name');
3233
$modal.find('input[name=from]').val(oldBranchName);
3334

35+
// display the warning that the branch which is chosen is the default branch
36+
const $warn = $modal.find('.default-branch-warning');
37+
toggleElem($warn, $(this).attr('data-is-default-branch') === 'true');
38+
3439
const $text = $modal.find('[data-rename-branch-to]');
3540
$text.text($text.attr('data-rename-branch-to').replace('%s', oldBranchName));
3641
});

0 commit comments

Comments
 (0)