-
-
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
base: main
Are you sure you want to change the base?
Fix GetCommitBranchStart
bug
#33298
Conversation
for _, commitID := range parts { | ||
branches, err := repo.getBranches(env, string(commitID), 2) | ||
if err != nil { | ||
return "", err | ||
} | ||
for _, b := range branches { | ||
if b != branch { | ||
return startCommitID, nil | ||
return string(commitID), nil |
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.
I am unable to understand what GetCommitBranchStart
is doing here ....
The old code seems to "return the last found one", the new code seems to "return the first found one"?
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.
I am unable to understand what
GetCommitBranchStart
is doing here ....
According to #31738, GetCommitBranchStart
is used to find the divergence commit of a newly created branch.
The old code seems to "return the last found one", the new code seems to "return the first found one"?
The old code returns "the first commit after the divergence point", but I think here we should return "the divergence point". Because "the first commit after the divergence point" may not exist. For example, it does not exist when we create a new branch without any changes.
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.
Could there be some comments (with some examples)?
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.
Sure. I'll try to add some comments and test cases.
@@ -466,7 +497,7 @@ func doProtectBranch(ctx APITestContext, branch, userToWhitelistPush, userToWhit | |||
// Check if master branch has been locked successfully | |||
flashCookie := ctx.Session.GetCookie(gitea_context.CookieNameFlash) | |||
assert.NotNil(t, flashCookie) | |||
assert.EqualValues(t, "success%3DBranch%2Bprotection%2Bfor%2Brule%2B%2522"+url.QueryEscape(branch)+"%2522%2Bhas%2Bbeen%2Bupdated.", flashCookie.Value) | |||
assert.EqualValues(t, "success%3DBranch%2Bprotection%2Bfor%2Brule%2B%2522"+url.QueryEscape(url.QueryEscape(branch))+"%2522%2Bhas%2Bbeen%2Bupdated.", flashCookie.Value) |
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.
I have to escape branch
twice here, otherwise the test will fail. The reason may be that we escaped the cookie value twice:
gitea/services/context/context.go
Line 184 in 7582eb0
if val := ctx.Flash.Encode(); val != "" { |
gitea/modules/web/middleware/cookie.go
Line 44 in 7582eb0
Value: url.QueryEscape(value), |
@@ -336,7 +366,7 @@ func doBranchProtectPRMerge(baseCtx *APITestContext, dstPath string) func(t *tes | |||
|
|||
// Protect branch without any whitelisting | |||
t.Run("ProtectBranchNoWhitelist", func(t *testing.T) { | |||
doProtectBranch(ctx, "protected", "", "", "") | |||
doProtectBranch(ctx, "protected", "", "", "", "") |
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 I found some other problems. Will the branch protection rule be created? Should this be doProtectBranch(ctx, "protected", "", "", "", "")(t)
?
Fix #33265