loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request 'fix: make branch protection work for new branches' (#5688) from gusted/forgejo-branch-protection-new-branch into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/5688
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>

+35
+11
modules/git/diff.go
··· 272 272 273 273 // GetAffectedFiles returns the affected files between two commits 274 274 func GetAffectedFiles(repo *Repository, oldCommitID, newCommitID string, env []string) ([]string, error) { 275 + objectFormat, err := repo.GetObjectFormat() 276 + if err != nil { 277 + return nil, err 278 + } 279 + 280 + // If the oldCommitID is empty, then we must assume its a new branch, so diff 281 + // against the empty tree. So all changes of this new branch are included. 282 + if oldCommitID == objectFormat.EmptyObjectID().String() { 283 + oldCommitID = objectFormat.EmptyTree().String() 284 + } 285 + 275 286 stdoutReader, stdoutWriter, err := os.Pipe() 276 287 if err != nil { 277 288 log.Error("Unable to create os.Pipe for %s", repo.Path)
+2
modules/testlogger/testlogger.go
··· 131 131 `:SSHLog() [E] ssh: Not allowed to push to protected branch protected. HookPreReceive(last) failed: internal API error response, status=403`, 132 132 // TestGit/HTTP/BranchProtectMerge 133 133 `:SSHLog() [E] ssh: branch protected is protected from force push. HookPreReceive(last) failed: internal API error response, status=403`, 134 + // TestGit/HTTP/BranchProtect 135 + `:SSHLog() [E] ssh: branch before-create-2 is protected from changing file protected-file-data-`, 134 136 // TestGit/HTTP/MergeFork/CreatePRAndMerge 135 137 `:DeleteBranchPost() [E] DeleteBranch: GetBranch: branch does not exist [repo_id: 1099 name: user2:master]`, // sqlite 136 138 "s/web/repo/branch.go:108:DeleteBranchPost() [E] DeleteBranch: GetBranch: branch does not exist [repo_id: 10000 name: user2:master]", // mysql
+22
tests/integration/git_test.go
··· 369 369 370 370 ctx := NewAPITestContext(t, baseCtx.Username, baseCtx.Reponame, auth_model.AccessTokenScopeWriteRepository) 371 371 372 + t.Run("PushToNewProtectedBranch", func(t *testing.T) { 373 + t.Run("CreateBranchProtected", doGitCreateBranch(dstPath, "before-create-1")) 374 + t.Run("ProtectProtectedBranch", doProtectBranch(ctx, "before-create-1", parameterProtectBranch{ 375 + "enable_push": "all", 376 + "apply_to_admins": "on", 377 + })) 378 + t.Run("PushProtectedBranch", doGitPushTestRepository(dstPath, "origin", "before-create-1")) 379 + 380 + t.Run("GenerateCommit", func(t *testing.T) { 381 + _, err := generateCommitWithNewData(littleSize, dstPath, "user2@example.com", "User Two", "protected-file-data-") 382 + require.NoError(t, err) 383 + }) 384 + 385 + t.Run("ProtectProtectedBranch", doProtectBranch(ctx, "before-create-2", parameterProtectBranch{ 386 + "enable_push": "all", 387 + "protected_file_patterns": "protected-file-data-*", 388 + "apply_to_admins": "on", 389 + })) 390 + 391 + doGitPushTestRepositoryFail(dstPath, "origin", "HEAD:before-create-2")(t) 392 + }) 393 + 372 394 t.Run("FailToPushToProtectedBranch", func(t *testing.T) { 373 395 t.Run("ProtectProtectedBranch", doProtectBranch(ctx, "protected")) 374 396 t.Run("Create modified-protected-branch", doGitCheckoutBranch(dstPath, "-b", "modified-protected-branch", "protected"))