9
9
10
10
"code.gitea.io/gitea/models"
11
11
"code.gitea.io/gitea/modules/git"
12
- "code.gitea.io/gitea/modules/log"
13
12
)
14
13
15
14
// GetBranch returns a branch by its name
@@ -74,39 +73,9 @@ func CreateNewBranch(doer *models.User, repo *models.Repository, oldBranchName,
74
73
return fmt .Errorf ("OldBranch: %s does not exist. Cannot create new branch from this" , oldBranchName )
75
74
}
76
75
77
- basePath , err := models .CreateTemporaryPath ("branch-maker" )
78
- if err != nil {
79
- return err
80
- }
81
- defer func () {
82
- if err := models .RemoveTemporaryPath (basePath ); err != nil {
83
- log .Error ("CreateNewBranch: RemoveTemporaryPath: %s" , err )
84
- }
85
- }()
86
-
87
- if err := git .Clone (repo .RepoPath (), basePath , git.CloneRepoOptions {
88
- Bare : true ,
89
- Shared : true ,
90
- }); err != nil {
91
- log .Error ("Failed to clone repository: %s (%v)" , repo .FullName (), err )
92
- return fmt .Errorf ("Failed to clone repository: %s (%v)" , repo .FullName (), err )
93
- }
94
-
95
- gitRepo , err := git .OpenRepository (basePath )
96
- if err != nil {
97
- log .Error ("Unable to open temporary repository: %s (%v)" , basePath , err )
98
- return fmt .Errorf ("Failed to open new temporary repository in: %s %v" , basePath , err )
99
- }
100
- defer gitRepo .Close ()
101
-
102
- if err = gitRepo .CreateBranch (branchName , oldBranchName ); err != nil {
103
- log .Error ("Unable to create branch: %s from %s. (%v)" , branchName , oldBranchName , err )
104
- return fmt .Errorf ("Unable to create branch: %s from %s. (%v)" , branchName , oldBranchName , err )
105
- }
106
-
107
- if err = git .Push (basePath , git.PushOptions {
108
- Remote : "origin" ,
109
- Branch : branchName ,
76
+ if err := git .Push (repo .RepoPath (), git.PushOptions {
77
+ Remote : repo .RepoPath (),
78
+ Branch : fmt .Sprintf ("%s:%s%s" , oldBranchName , git .BranchPrefix , branchName ),
110
79
Env : models .PushingEnvironment (doer , repo ),
111
80
}); err != nil {
112
81
if git .IsErrPushOutOfDate (err ) || git .IsErrPushRejected (err ) {
@@ -124,39 +93,10 @@ func CreateNewBranchFromCommit(doer *models.User, repo *models.Repository, commi
124
93
if err := checkBranchName (repo , branchName ); err != nil {
125
94
return err
126
95
}
127
- basePath , err := models .CreateTemporaryPath ("branch-maker" )
128
- if err != nil {
129
- return err
130
- }
131
- defer func () {
132
- if err := models .RemoveTemporaryPath (basePath ); err != nil {
133
- log .Error ("CreateNewBranchFromCommit: RemoveTemporaryPath: %s" , err )
134
- }
135
- }()
136
-
137
- if err := git .Clone (repo .RepoPath (), basePath , git.CloneRepoOptions {
138
- Bare : true ,
139
- Shared : true ,
140
- }); err != nil {
141
- log .Error ("Failed to clone repository: %s (%v)" , repo .FullName (), err )
142
- return fmt .Errorf ("Failed to clone repository: %s (%v)" , repo .FullName (), err )
143
- }
144
-
145
- gitRepo , err := git .OpenRepository (basePath )
146
- if err != nil {
147
- log .Error ("Unable to open temporary repository: %s (%v)" , basePath , err )
148
- return fmt .Errorf ("Failed to open new temporary repository in: %s %v" , basePath , err )
149
- }
150
- defer gitRepo .Close ()
151
-
152
- if err = gitRepo .CreateBranch (branchName , commit ); err != nil {
153
- log .Error ("Unable to create branch: %s from %s. (%v)" , branchName , commit , err )
154
- return fmt .Errorf ("Unable to create branch: %s from %s. (%v)" , branchName , commit , err )
155
- }
156
96
157
- if err = git .Push (basePath , git.PushOptions {
158
- Remote : "origin" ,
159
- Branch : branchName ,
97
+ if err : = git .Push (repo . RepoPath () , git.PushOptions {
98
+ Remote : repo . RepoPath () ,
99
+ Branch : fmt . Sprintf ( "%s:%s%s" , commit , git . BranchPrefix , branchName ) ,
160
100
Env : models .PushingEnvironment (doer , repo ),
161
101
}); err != nil {
162
102
if git .IsErrPushOutOfDate (err ) || git .IsErrPushRejected (err ) {
0 commit comments