-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add API Endpoint for Branch Creation #11607
Add API Endpoint for Branch Creation #11607
Conversation
Thanks for PR :) It looks like you have modified the vendors/modules.txt file, this is likely due to working with an older version of Go. Could you revert your changes from that specific file? |
e34cddc
to
4aafa8b
Compare
Oh sorry, I amended |
997c392
to
f2978d9
Compare
since you dont use RepoRefByType you have to:
and since repo_module.CreateNewBranch return no specific error if the OldBranch not exist,
Or:
After this Only some Tests are missing :) |
and a format question why do you created a second function (CreateRepoBranch) if you can just put the code into CreateBranch. It would make sence if you like to re-use CreateRepoBranch but it is only used once |
@tle-huu thanks for the pull, after the points above are resolved I think its good to go ;) |
0d1bd15
to
2ce8212
Compare
OK, one thing left Tests |
I have trouble running the tests locally, getting an internal error related to pushing / pre-receive hooks (when I run make test-pgsql):
EDIT: Ok looks like it is not just locally.. |
ac34af1
to
7604857
Compare
the test itself looks good, so there is an issue with the CreateBranch implementation |
Looks like it comes from an internal pre-receive hook (when I overwrite the hook in the gitea-repositories-meta repos it works), triggered because CreateNewBranch creates the new branch and then push it. |
Zeripaths Idear of creating a temporary repo sound a good solution for this ... |
1e635de
to
98245b4
Compare
@@ -71,7 +71,9 @@ func CreateNewBranch(doer *models.User, repo *models.Repository, oldBranchName, | |||
} | |||
|
|||
if !git.IsBranchExist(repo.RepoPath(), oldBranchName) { | |||
return fmt.Errorf("OldBranch: %s does not exist. Cannot create new branch from this", oldBranchName) | |||
return models.ErrBranchDoesNotExist{ |
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.
Have you checked every call to CreateNewBranch and made sure they handle your new error correctly?
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.
The other place where CreateNewBranch is used is in routers/repo/branch.go CreateBranch function and uses the ctx.Repo.BranchName as the "OldBranchName".
It does not "models.isErr" it but treats it as a ServerErr. Should we add a check there as well ? If so, should we do it in this PR or in another CL ?
Issue: go-gitea#11376 This commit introduces an API endpoint for branch creation. The added route is POST /repos/{owner}/{repo}/branches. A JSON with the name of the new branch and the name of the old branch is required as parameters. Signed-off-by: Terence Le Huu Phuong <[email protected]>
- Made the CreateNewBranch function return an errBranchDoesNotExist error when the OldBranch does not exist - Made the CreateBranch API function checks that the repository is not empty and that branch exists.
fine-tune test env resetting - Added api test for CreateBranch - Used resetFixture instead of the more general prepareTestEnv in the repo_branch_test CreateBranch tests
3758d73
to
9651305
Compare
Sorry, I accidentally "merged" master into this branch. I rebased on master (but this is equivalent to 5df39561490e79cb3237d541cf906c09eab8cfed) |
merging master int this (or hit the "update" button) is the normal way to let pulls be up-to-date |
make lg-tm work |
* [FEATURE] [API] Add Endpoint for Branch Creation Issue: go-gitea#11376 This commit introduces an API endpoint for branch creation. The added route is POST /repos/{owner}/{repo}/branches. A JSON with the name of the new branch and the name of the old branch is required as parameters. Signed-off-by: Terence Le Huu Phuong <[email protected]> * Put all the logic into CreateBranch and removed CreateRepoBranch * - Added the error ErrBranchDoesNotExist in error.go - Made the CreateNewBranch function return an errBranchDoesNotExist error when the OldBranch does not exist - Made the CreateBranch API function checks that the repository is not empty and that branch exists. * - Added a resetFixtures helper function in integration_test.go to fine-tune test env resetting - Added api test for CreateBranch - Used resetFixture instead of the more general prepareTestEnv in the repo_branch_test CreateBranch tests * Moved the resetFixtures call inside the loop for APICreateBranch function * Put the prepareTestEnv back in repo_branch_test * fix import order/sort api branch test Co-authored-by: zeripath <[email protected]>
Issue: #11376
This commit introduces an API endpoint for branch creation.
The added route is POST /repos/{owner}/{repo}/branches.
A JSON with the name of the new branch and the name of the "old" branch is required as parameters.