-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Fix GetCommitBranchStart
bug
#33298
Open
Zettat123
wants to merge
1
commit into
go-gitea:main
Choose a base branch
from
Zettat123:bugfix/issue-33265
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+49
−30
Open
Fix GetCommitBranchStart
bug
#33298
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,7 @@ func testGitGeneral(t *testing.T, u *url.URL) { | |
mediaTest(t, &httpContext, pushedFilesStandard[0], pushedFilesStandard[1], pushedFilesLFS[0], pushedFilesLFS[1]) | ||
|
||
t.Run("CreateAgitFlowPull", doCreateAgitFlowPull(dstPath, &httpContext, "test/head")) | ||
t.Run("CreateProtectedBranch", doCreateProtectedBranch(&httpContext, dstPath)) | ||
t.Run("BranchProtectMerge", doBranchProtectPRMerge(&httpContext, dstPath)) | ||
t.Run("AutoMerge", doAutoPRMerge(&httpContext, dstPath)) | ||
t.Run("CreatePRAndSetManuallyMerged", doCreatePRAndSetManuallyMerged(httpContext, httpContext, dstPath, "master", "test-manually-merge")) | ||
|
@@ -121,6 +122,7 @@ func testGitGeneral(t *testing.T, u *url.URL) { | |
mediaTest(t, &sshContext, pushedFilesStandard[0], pushedFilesStandard[1], pushedFilesLFS[0], pushedFilesLFS[1]) | ||
|
||
t.Run("CreateAgitFlowPull", doCreateAgitFlowPull(dstPath, &sshContext, "test/head2")) | ||
t.Run("CreateProtectedBranch", doCreateProtectedBranch(&sshContext, dstPath)) | ||
t.Run("BranchProtectMerge", doBranchProtectPRMerge(&sshContext, dstPath)) | ||
t.Run("MergeFork", func(t *testing.T) { | ||
defer tests.PrintCurrentTest(t)() | ||
|
@@ -325,6 +327,34 @@ func generateCommitWithNewData(size int, repoPath, email, fullName, prefix strin | |
return filepath.Base(tmpFile.Name()), err | ||
} | ||
|
||
func doCreateProtectedBranch(baseCtx *APITestContext, dstPath string) func(t *testing.T) { | ||
return func(t *testing.T) { | ||
defer tests.PrintCurrentTest(t)() | ||
ctx := NewAPITestContext(t, baseCtx.Username, baseCtx.Reponame, auth_model.AccessTokenScopeWriteRepository) | ||
|
||
t.Run("ProtectBranchWithFilePatterns", doProtectBranch(ctx, "release-*", baseCtx.Username, "", "", "config*")) | ||
|
||
// push a new branch without any new commits | ||
t.Run("CreateProtectedBranch-NoChanges", doGitCreateBranch(dstPath, "release-v1.0")) | ||
t.Run("PushProtectedBranch-NoChanges", doGitPushTestRepository(dstPath, "origin", "release-v1.0")) | ||
t.Run("CheckoutMaster-NoChanges", doGitCheckoutBranch(dstPath, "master")) | ||
|
||
// push a new branch with a new unprotected file | ||
t.Run("CreateProtectedBranch-UnprotectedFile", doGitCreateBranch(dstPath, "release-v2.0")) | ||
_, err := generateCommitWithNewData(testFileSizeSmall, dstPath, "[email protected]", "User Two", "abc.txt") | ||
assert.NoError(t, err) | ||
t.Run("PushProtectedBranch-UnprotectedFile", doGitPushTestRepository(dstPath, "origin", "release-v2.0")) | ||
t.Run("CheckoutMaster-UnprotectedFile", doGitCheckoutBranch(dstPath, "master")) | ||
|
||
// push a new branch with a new protected file | ||
t.Run("CreateProtectedBranch-ProtectedFile", doGitCreateBranch(dstPath, "release-v3.0")) | ||
_, err = generateCommitWithNewData(testFileSizeSmall, dstPath, "[email protected]", "User Two", "config") | ||
assert.NoError(t, err) | ||
t.Run("PushProtectedBranch-ProtectedFile", doGitPushTestRepositoryFail(dstPath, "origin", "release-v3.0")) | ||
t.Run("CheckoutMaster-ProtectedFile", doGitCheckoutBranch(dstPath, "master")) | ||
} | ||
} | ||
|
||
func doBranchProtectPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) { | ||
return func(t *testing.T) { | ||
defer tests.PrintCurrentTest(t)() | ||
|
@@ -334,27 +364,23 @@ func doBranchProtectPRMerge(baseCtx *APITestContext, dstPath string) func(t *tes | |
ctx := NewAPITestContext(t, baseCtx.Username, baseCtx.Reponame, auth_model.AccessTokenScopeWriteRepository) | ||
|
||
// Protect branch without any whitelisting | ||
t.Run("ProtectBranchNoWhitelist", func(t *testing.T) { | ||
doProtectBranch(ctx, "protected", "", "", "") | ||
}) | ||
t.Run("ProtectBranchNoWhitelist", doProtectBranch(ctx, "protected", "", "", "", "")) | ||
|
||
// Try to push without permissions, which should fail | ||
t.Run("TryPushWithoutPermissions", func(t *testing.T) { | ||
_, err := generateCommitWithNewData(testFileSizeSmall, dstPath, "[email protected]", "User Two", "branch-data-file-") | ||
assert.NoError(t, err) | ||
doGitPushTestRepositoryFail(dstPath, "origin", "protected") | ||
doGitPushTestRepositoryFail(dstPath, "origin", "protected")(t) | ||
}) | ||
|
||
// Set up permissions for normal push but not force push | ||
t.Run("SetupNormalPushPermissions", func(t *testing.T) { | ||
doProtectBranch(ctx, "protected", baseCtx.Username, "", "") | ||
}) | ||
t.Run("SetupNormalPushPermissions", doProtectBranch(ctx, "protected", baseCtx.Username, "", "", "")) | ||
|
||
// Normal push should work | ||
t.Run("NormalPushWithPermissions", func(t *testing.T) { | ||
_, err := generateCommitWithNewData(testFileSizeSmall, dstPath, "[email protected]", "User Two", "branch-data-file-") | ||
assert.NoError(t, err) | ||
doGitPushTestRepository(dstPath, "origin", "protected") | ||
doGitPushTestRepository(dstPath, "origin", "protected")(t) | ||
}) | ||
|
||
// Try to force push without force push permissions, which should fail | ||
|
@@ -364,30 +390,22 @@ func doBranchProtectPRMerge(baseCtx *APITestContext, dstPath string) func(t *tes | |
_, err := generateCommitWithNewData(testFileSizeSmall, dstPath, "[email protected]", "User Two", "branch-data-file-new") | ||
assert.NoError(t, err) | ||
}) | ||
doGitPushTestRepositoryFail(dstPath, "-f", "origin", "protected") | ||
doGitPushTestRepositoryFail(dstPath, "-f", "origin", "protected")(t) | ||
}) | ||
|
||
// Set up permissions for force push but not normal push | ||
t.Run("SetupForcePushPermissions", func(t *testing.T) { | ||
doProtectBranch(ctx, "protected", "", baseCtx.Username, "") | ||
}) | ||
t.Run("SetupForcePushPermissions", doProtectBranch(ctx, "protected", "", baseCtx.Username, "", "")) | ||
|
||
// Try to force push without normal push permissions, which should fail | ||
t.Run("ForcePushWithoutNormalPermissions", func(t *testing.T) { | ||
doGitPushTestRepositoryFail(dstPath, "-f", "origin", "protected") | ||
}) | ||
t.Run("ForcePushWithoutNormalPermissions", doGitPushTestRepositoryFail(dstPath, "-f", "origin", "protected")) | ||
|
||
// Set up permissions for normal and force push (both are required to force push) | ||
t.Run("SetupNormalAndForcePushPermissions", func(t *testing.T) { | ||
doProtectBranch(ctx, "protected", baseCtx.Username, baseCtx.Username, "") | ||
}) | ||
t.Run("SetupNormalAndForcePushPermissions", doProtectBranch(ctx, "protected", baseCtx.Username, baseCtx.Username, "", "")) | ||
|
||
// Force push should now work | ||
t.Run("ForcePushWithPermissions", func(t *testing.T) { | ||
doGitPushTestRepository(dstPath, "-f", "origin", "protected") | ||
}) | ||
t.Run("ForcePushWithPermissions", doGitPushTestRepository(dstPath, "-f", "origin", "protected")) | ||
|
||
t.Run("ProtectProtectedBranchNoWhitelist", doProtectBranch(ctx, "protected", "", "", "")) | ||
t.Run("ProtectProtectedBranchNoWhitelist", doProtectBranch(ctx, "protected", "", "", "", "")) | ||
t.Run("PushToUnprotectedBranch", doGitPushTestRepository(dstPath, "origin", "protected:unprotected")) | ||
var pr api.PullRequest | ||
var err error | ||
|
@@ -409,14 +427,14 @@ func doBranchProtectPRMerge(baseCtx *APITestContext, dstPath string) func(t *tes | |
t.Run("MergePR", doAPIMergePullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr.Index)) | ||
t.Run("PullProtected", doGitPull(dstPath, "origin", "protected")) | ||
|
||
t.Run("ProtectProtectedBranchUnprotectedFilePaths", doProtectBranch(ctx, "protected", "", "", "unprotected-file-*")) | ||
t.Run("ProtectProtectedBranchUnprotectedFilePaths", doProtectBranch(ctx, "protected", "", "", "unprotected-file-*", "")) | ||
t.Run("GenerateCommit", func(t *testing.T) { | ||
_, err := generateCommitWithNewData(testFileSizeSmall, dstPath, "[email protected]", "User Two", "unprotected-file-") | ||
assert.NoError(t, err) | ||
}) | ||
t.Run("PushUnprotectedFilesToProtectedBranch", doGitPushTestRepository(dstPath, "origin", "protected")) | ||
|
||
t.Run("ProtectProtectedBranchWhitelist", doProtectBranch(ctx, "protected", baseCtx.Username, "", "")) | ||
t.Run("ProtectProtectedBranchWhitelist", doProtectBranch(ctx, "protected", baseCtx.Username, "", "", "")) | ||
|
||
t.Run("CheckoutMaster", doGitCheckoutBranch(dstPath, "master")) | ||
t.Run("CreateBranchForced", doGitCreateBranch(dstPath, "toforce")) | ||
|
@@ -431,7 +449,7 @@ func doBranchProtectPRMerge(baseCtx *APITestContext, dstPath string) func(t *tes | |
} | ||
} | ||
|
||
func doProtectBranch(ctx APITestContext, branch, userToWhitelistPush, userToWhitelistForcePush, unprotectedFilePatterns string) func(t *testing.T) { | ||
func doProtectBranch(ctx APITestContext, branch, userToWhitelistPush, userToWhitelistForcePush, unprotectedFilePatterns, protectedFilePatterns string) func(t *testing.T) { | ||
// We are going to just use the owner to set the protection. | ||
return func(t *testing.T) { | ||
csrf := GetUserCSRFToken(t, ctx.Session) | ||
|
@@ -440,6 +458,7 @@ func doProtectBranch(ctx APITestContext, branch, userToWhitelistPush, userToWhit | |
"_csrf": csrf, | ||
"rule_name": branch, | ||
"unprotected_file_patterns": unprotectedFilePatterns, | ||
"protected_file_patterns": protectedFilePatterns, | ||
} | ||
|
||
if userToWhitelistPush != "" { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can use len(branches) >1 here