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 <matti@mdranta.net> Co-authored-by: Jason Song <i@wolfogre.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
parent
0ca1958e1a
commit
0c657112a3
3 changed files with 11 additions and 0 deletions
|
@ -2412,6 +2412,7 @@ branch.included_desc = This branch is part of the default branch
|
||||||
branch.included = Included
|
branch.included = Included
|
||||||
branch.create_new_branch = Create branch from branch:
|
branch.create_new_branch = Create branch from branch:
|
||||||
branch.confirm_create_branch = Create branch
|
branch.confirm_create_branch = Create branch
|
||||||
|
branch.warning_rename_default_branch = You are renaming the default branch.
|
||||||
branch.rename_branch_to = Rename "%s" to:
|
branch.rename_branch_to = Rename "%s" to:
|
||||||
branch.confirm_rename_branch = Rename branch
|
branch.confirm_rename_branch = Rename branch
|
||||||
branch.create_branch_operation = Create branch
|
branch.create_branch_operation = Create branch
|
||||||
|
|
|
@ -52,6 +52,7 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not $.IsMirror)}}
|
{{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not $.IsMirror)}}
|
||||||
<button class="ui tertiary button show-modal show-rename-branch-modal gt-mx-3"
|
<button class="ui tertiary button show-modal show-rename-branch-modal gt-mx-3"
|
||||||
|
data-is-default-branch="true"
|
||||||
data-modal="#rename-branch-modal"
|
data-modal="#rename-branch-modal"
|
||||||
data-old-branch-name="{{$.DefaultBranch}}"
|
data-old-branch-name="{{$.DefaultBranch}}"
|
||||||
data-tooltip-content="{{$.locale.Tr "repo.branch.rename" ($.DefaultBranch)}}"
|
data-tooltip-content="{{$.locale.Tr "repo.branch.rename" ($.DefaultBranch)}}"
|
||||||
|
@ -158,6 +159,7 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not $.IsMirror)}}
|
{{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not $.IsMirror)}}
|
||||||
<button class="ui tertiary button show-modal show-rename-branch-modal gt-mx-3"
|
<button class="ui tertiary button show-modal show-rename-branch-modal gt-mx-3"
|
||||||
|
data-is-default-branch="false"
|
||||||
data-old-branch-name="{{.Name}}"
|
data-old-branch-name="{{.Name}}"
|
||||||
data-modal="#rename-branch-modal"
|
data-modal="#rename-branch-modal"
|
||||||
data-tooltip-content="{{$.locale.Tr "repo.branch.rename" (.Name)}}"
|
data-tooltip-content="{{$.locale.Tr "repo.branch.rename" (.Name)}}"
|
||||||
|
@ -229,6 +231,9 @@
|
||||||
<form class="ui form" action="{{$.Repository.Link}}/settings/rename_branch" method="post">
|
<form class="ui form" action="{{$.Repository.Link}}/settings/rename_branch" method="post">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
{{.CsrfTokenHtml}}
|
{{.CsrfTokenHtml}}
|
||||||
|
<div class="field default-branch-warning">
|
||||||
|
<span class="text red">{{.locale.Tr "repo.branch.warning_raname_default_branch"}}</span>
|
||||||
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<span class="text" data-rename-branch-to="{{.locale.Tr "repo.branch.rename_branch_to"}}"></span>
|
<span class="text" data-rename-branch-to="{{.locale.Tr "repo.branch.rename_branch_to"}}"></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
|
import {toggleElem} from '../utils/dom.js';
|
||||||
|
|
||||||
export function initRepoBranchButton() {
|
export function initRepoBranchButton() {
|
||||||
initRepoCreateBranchButton();
|
initRepoCreateBranchButton();
|
||||||
|
@ -31,6 +32,10 @@ function initRepoRenameBranchButton() {
|
||||||
const oldBranchName = $(this).attr('data-old-branch-name');
|
const oldBranchName = $(this).attr('data-old-branch-name');
|
||||||
$modal.find('input[name=from]').val(oldBranchName);
|
$modal.find('input[name=from]').val(oldBranchName);
|
||||||
|
|
||||||
|
// display the warning that the branch which is chosen is the default branch
|
||||||
|
const $warn = $modal.find('.default-branch-warning');
|
||||||
|
toggleElem($warn, $(this).attr('data-is-default-branch') === 'true');
|
||||||
|
|
||||||
const $text = $modal.find('[data-rename-branch-to]');
|
const $text = $modal.find('[data-rename-branch-to]');
|
||||||
$text.text($text.attr('data-rename-branch-to').replace('%s', oldBranchName));
|
$text.text($text.attr('data-rename-branch-to').replace('%s', oldBranchName));
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue