aboutsummaryrefslogtreecommitdiffstats
path: root/services/repository/branch.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-12-28 15:28:57 +0800
committerGitHub <noreply@github.com>2023-12-28 15:28:57 +0800
commit921df1cbad83dcba37ff12cba88c7d3a69f8588b (patch)
tree2f7e2ad14f2cd284a2740c8198605d5ccc132de9 /services/repository/branch.go
parent4cd666d7dcc7531806cde65c6468f93529cc23dd (diff)
downloadgitea-921df1cbad83dcba37ff12cba88c7d3a69f8588b.tar.gz
gitea-921df1cbad83dcba37ff12cba88c7d3a69f8588b.zip
Remove unnecessary syncbranchToDB with tests (#28624)
#28361 introduced `syncBranchToDB` in `CreateNewBranchFromCommit`. This PR will revert the change because it's unnecessary. Every push will already be checked by `syncBranchToDB`. This PR also created a test to ensure it's right.
Diffstat (limited to 'services/repository/branch.go')
-rw-r--r--services/repository/branch.go29
1 files changed, 9 insertions, 20 deletions
diff --git a/services/repository/branch.go b/services/repository/branch.go
index dca938444a..7254778763 100644
--- a/services/repository/branch.go
+++ b/services/repository/branch.go
@@ -276,28 +276,17 @@ func CreateNewBranchFromCommit(ctx context.Context, doer *user_model.User, repo
return err
}
- return db.WithTx(ctx, func(ctx context.Context) error {
- commit, err := gitRepo.GetCommit(commitID)
- if err != nil {
- return err
- }
- // database operation should be done before git operation so that we can rollback if git operation failed
- if err := syncBranchToDB(ctx, repo.ID, doer.ID, branchName, commit); err != nil {
+ if err := git.Push(ctx, repo.RepoPath(), git.PushOptions{
+ Remote: repo.RepoPath(),
+ Branch: fmt.Sprintf("%s:%s%s", commitID, git.BranchPrefix, branchName),
+ Env: repo_module.PushingEnvironment(doer, repo),
+ }); err != nil {
+ if git.IsErrPushOutOfDate(err) || git.IsErrPushRejected(err) {
return err
}
-
- if err := git.Push(ctx, repo.RepoPath(), git.PushOptions{
- Remote: repo.RepoPath(),
- Branch: fmt.Sprintf("%s:%s%s", commitID, git.BranchPrefix, branchName),
- Env: repo_module.PushingEnvironment(doer, repo),
- }); err != nil {
- if git.IsErrPushOutOfDate(err) || git.IsErrPushRejected(err) {
- return err
- }
- return fmt.Errorf("push: %w", err)
- }
- return nil
- })
+ return fmt.Errorf("push: %w", err)
+ }
+ return nil
}
// RenameBranch rename a branch