mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-09 17:37:20 -06:00
enhance: enable DEFAULT_DELETE_BRANCH_AFTER_MERGE by default for new repos (#39975)
Switch the `DEFAULT_DELETE_BRANCH_AFTER_MERGE` default from https://github.com/go-gitea/gitea/pull/36917 to `true`, saving users a click on merge for the most common action that deletes the PR branch on merge. Docs: https://gitea.com/gitea/docs/pulls/608
This commit is contained in:
@@ -1242,7 +1242,7 @@ LEVEL = Info
|
||||
;DELAY_CHECK_FOR_INACTIVE_DAYS = 7
|
||||
;;
|
||||
;; Set the default value for "Delete pull request branch after merge by default" for new repositories
|
||||
;DEFAULT_DELETE_BRANCH_AFTER_MERGE = false
|
||||
;DEFAULT_DELETE_BRANCH_AFTER_MERGE = true
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
@@ -211,6 +211,7 @@ var (
|
||||
AddCoCommitterTrailers: true,
|
||||
RetargetChildrenOnMerge: true,
|
||||
DelayCheckForInactiveDays: 7,
|
||||
DefaultDeleteBranchAfterMerge: true,
|
||||
DefaultTitleSource: RepoPRTitleSourceAuto,
|
||||
},
|
||||
|
||||
|
||||
@@ -18,6 +18,6 @@ test('merge box merges a pull request', async ({page, request}) => {
|
||||
await page.getByRole('button', {name: 'Create merge commit'}).click();
|
||||
await page.locator('form.form-fetch-action').getByRole('button', {name: 'Create merge commit'}).click();
|
||||
|
||||
await expect(page.getByText(/successfully merged/i)).toBeVisible();
|
||||
await expect(page.getByText('Merged', {exact: true})).toBeVisible();
|
||||
await assertNoJsError(page);
|
||||
});
|
||||
|
||||
@@ -270,45 +270,36 @@ func TestAPIMergePull(t *testing.T) {
|
||||
t.Run("Normal", func(t *testing.T) {
|
||||
newBranch := "test-pull-1"
|
||||
prDTO := createTestBranchPR(t, newBranch)
|
||||
performMerge(t, prDTO.Index, map[string]any{"do": "merge"})
|
||||
performMerge(t, prDTO.Index, map[string]any{"do": "merge", "delete_branch_after_merge": false})
|
||||
checkBranchExists(t, newBranch, http.StatusOK)
|
||||
// try to merge again, make sure we cannot perform a merge on the same PR
|
||||
performMerge(t, prDTO.Index, map[string]any{"do": "merge"}, http.StatusMethodNotAllowed)
|
||||
})
|
||||
|
||||
t.Run("DeleteBranchAfterMergePassedByFormField", func(t *testing.T) {
|
||||
t.Run("DeleteBranchAfterMergeByDefault", func(t *testing.T) {
|
||||
newBranch := "test-pull-2"
|
||||
prDTO := createTestBranchPR(t, newBranch)
|
||||
performMerge(t, prDTO.Index, map[string]any{"do": "merge", "delete_branch_after_merge": true})
|
||||
performMerge(t, prDTO.Index, map[string]any{"do": "merge"})
|
||||
checkBranchExists(t, newBranch, http.StatusNotFound)
|
||||
})
|
||||
|
||||
updateRepoUnitDefaultDeleteBranchAfterMerge := func(t *testing.T, repo *repo_model.Repository, value bool) {
|
||||
t.Run("DeleteBranchAfterMergeDisabledByRepoSettings", func(t *testing.T) {
|
||||
prUnit, err := repo.GetUnit(t.Context(), unit_model.TypePullRequests)
|
||||
require.NoError(t, err)
|
||||
|
||||
prUnit.PullRequestsConfig().DefaultDeleteBranchAfterMerge = value
|
||||
prUnit.PullRequestsConfig().DefaultDeleteBranchAfterMerge = false
|
||||
require.NoError(t, repo_service.UpdateRepositoryUnits(t.Context(), repo, []repo_model.RepoUnit{{
|
||||
RepoID: repo.ID,
|
||||
Type: unit_model.TypePullRequests,
|
||||
Config: prUnit.PullRequestsConfig(),
|
||||
}}, nil))
|
||||
}
|
||||
|
||||
t.Run("DeleteBranchAfterMergePassedByRepoSettings", func(t *testing.T) {
|
||||
newBranch := "test-pull-3"
|
||||
prDTO := createTestBranchPR(t, newBranch)
|
||||
updateRepoUnitDefaultDeleteBranchAfterMerge(t, repo, true)
|
||||
performMerge(t, prDTO.Index, map[string]any{"do": "merge"})
|
||||
checkBranchExists(t, newBranch, http.StatusNotFound)
|
||||
})
|
||||
keptPR := createTestBranchPR(t, "test-pull-3")
|
||||
performMerge(t, keptPR.Index, map[string]any{"do": "merge"})
|
||||
checkBranchExists(t, "test-pull-3", http.StatusOK)
|
||||
|
||||
t.Run("DeleteBranchAfterMergeFormFieldIsSetButNotRepoSettings", func(t *testing.T) {
|
||||
newBranch := "test-pull-4"
|
||||
prDTO := createTestBranchPR(t, newBranch)
|
||||
updateRepoUnitDefaultDeleteBranchAfterMerge(t, repo, false)
|
||||
performMerge(t, prDTO.Index, map[string]any{"do": "merge", "delete_branch_after_merge": true})
|
||||
checkBranchExists(t, newBranch, http.StatusNotFound)
|
||||
deletedPR := createTestBranchPR(t, "test-pull-4")
|
||||
performMerge(t, deletedPR.Index, map[string]any{"do": "merge", "delete_branch_after_merge": true})
|
||||
checkBranchExists(t, "test-pull-4", http.StatusNotFound)
|
||||
})
|
||||
|
||||
t.Run("SquashMergePreservesFormMessage", func(t *testing.T) {
|
||||
|
||||
@@ -1215,7 +1215,6 @@ func TestPullSquashMessage(t *testing.T) {
|
||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
user2Session := loginUser(t, user2.Name)
|
||||
|
||||
defer test.MockVariableValue(&setting.Repository.PullRequest.DefaultSquashMergeMessage, "COMMIT_MESSAGES")()
|
||||
defer test.MockVariableValue(&setting.Repository.PullRequest.DefaultMergeMessageSize, 80)()
|
||||
|
||||
repo, err := repo_service.CreateRepository(t.Context(), user2, user2, repo_service.CreateRepoOptions{
|
||||
@@ -1226,6 +1225,14 @@ func TestPullSquashMessage(t *testing.T) {
|
||||
DefaultBranch: "main",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
prUnit, err := repo.GetUnit(t.Context(), unit_model.TypePullRequests)
|
||||
require.NoError(t, err)
|
||||
prUnit.PullRequestsConfig().DefaultSquashMergeMessage = repo_model.SquashMergeMessageCommitMessages
|
||||
require.NoError(t, repo_service.UpdateRepositoryUnits(t.Context(), repo, []repo_model.RepoUnit{{
|
||||
RepoID: repo.ID,
|
||||
Type: unit_model.TypePullRequests,
|
||||
Config: prUnit.PullRequestsConfig(),
|
||||
}}, nil))
|
||||
|
||||
type commitInfo struct {
|
||||
userName string
|
||||
@@ -1352,8 +1359,6 @@ Co-authored-by: user4 <user4@example.com>
|
||||
pullRequest.Issue.Content = "PR description"
|
||||
pullRequest.BaseRepo = repo
|
||||
|
||||
prUnit, err := repo.GetUnit(t.Context(), unit_model.TypePullRequests)
|
||||
require.NoError(t, err)
|
||||
for style, expected := range map[repo_model.SquashMergeMessage]string{
|
||||
repo_model.SquashMergeMessageBlank: "",
|
||||
repo_model.SquashMergeMessagePRBody: "PR description",
|
||||
@@ -1366,7 +1371,6 @@ Co-authored-by: user4 <user4@example.com>
|
||||
})
|
||||
|
||||
t.Run("API squash merge without message uses repository default", func(t *testing.T) {
|
||||
defer test.MockVariableValue(&setting.Repository.PullRequest.DefaultSquashMergeMessage, "PR_BODY")()
|
||||
token := getTokenForLoggedInUser(t, user2Session, auth_model.AccessTokenScopeWriteRepository)
|
||||
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/pulls/1/merge", user2.Name, repo.Name), map[string]string{"do": "squash"}).AddTokenAuth(token)
|
||||
MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
Reference in New Issue
Block a user