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:
sillyguodong 2023-05-05 06:54:38 +08:00 committed by GitHub
parent 0ca1958e1a
commit 0c657112a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 0 deletions

View file

@ -1,4 +1,5 @@
import $ from 'jquery';
import {toggleElem} from '../utils/dom.js';
export function initRepoBranchButton() {
initRepoCreateBranchButton();
@ -31,6 +32,10 @@ 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 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]');
$text.text($text.attr('data-rename-branch-to').replace('%s', oldBranchName));
});