Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display warning when user try to rename default branch #24512

Merged
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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_rename_default_branch = You are trying to rename the default branch.
sillyguodong marked this conversation as resolved.
Show resolved Hide resolved
branch.rename_branch_to = Rename "%s" to:
branch.confirm_rename_branch = Rename branch
branch.create_branch_operation = Create branch
Expand Down
5 changes: 5 additions & 0 deletions templates/repo/branch/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
{{end}}
{{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not $.IsMirror)}}
<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-old-branch-name="{{$.DefaultBranch}}"
data-tooltip-content="{{$.locale.Tr "repo.branch.rename" ($.DefaultBranch)}}"
Expand Down Expand Up @@ -158,6 +159,7 @@
{{end}}
{{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not $.IsMirror)}}
<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-modal="#rename-branch-modal"
data-tooltip-content="{{$.locale.Tr "repo.branch.rename" (.Name)}}"
Expand Down Expand Up @@ -229,6 +231,9 @@
<form class="ui form" action="{{$.Repository.Link}}/settings/rename_branch" method="post">
<div class="content">
{{.CsrfTokenHtml}}
<div class="field default-branch-warning">
<span class="text red">{{.locale.Tr "repo.branch.warning_raname_default_branch"}}</span>
Copy link
Contributor

@wxiaoguang wxiaoguang May 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to point out again (I have left too many trivial comments for this PR):

here , warning_r[a]name_default_branch, above: warning_r[e]name_default_branch

Please be careful!!!! And wolfogre has told you "And the typo raname needs to be fixed elsewhere as well."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the mistake, should I create a PR to fix the typo?

</div>
<div class="field">
<span class="text" data-rename-branch-to="{{.locale.Tr "repo.branch.rename_branch_to"}}"></span>
</div>
Expand Down
6 changes: 6 additions & 0 deletions web_src/js/features/repo-branch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import $ from 'jquery';
import {hideElem, showElem} from '../utils/dom.js';

export function initRepoBranchButton() {
initRepoCreateBranchButton();
Expand Down Expand Up @@ -31,6 +32,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 chosen is the default branch
const $warn = $modal.find('.default-branch-warning');
if ($(this).attr('data-is-default-branch') !== 'true') hideElem($warn);
else showElem($warn);
sillyguodong marked this conversation as resolved.
Show resolved Hide resolved

const $text = $modal.find('[data-rename-branch-to]');
$text.text($text.attr('data-rename-branch-to').replace('%s', oldBranchName));
});
Expand Down