@@ -101,36 +101,40 @@ func (repo *Repository) CreateNewBranch(doer *User, oldBranchName, branchName st
101
101
}
102
102
}
103
103
104
- return WithTemporaryPath ("branch-maker" , func (basePath string ) error {
105
- if err := git .Clone (repo .RepoPath (), basePath , git.CloneRepoOptions {
106
- Bare : true ,
107
- Shared : true ,
108
- }); err != nil {
109
- log .Error ("Failed to clone repository: %s (%v)" , repo .FullName (), err )
110
- return fmt .Errorf ("Failed to clone repository: %s (%v)" , repo .FullName (), err )
111
- }
104
+ basePath , err := CreateTemporaryPath ("branch-maker" )
105
+ if err != nil {
106
+ return err
107
+ }
108
+ defer RemoveTemporaryPath (basePath )
109
+
110
+ if err := git .Clone (repo .RepoPath (), basePath , git.CloneRepoOptions {
111
+ Bare : true ,
112
+ Shared : true ,
113
+ }); err != nil {
114
+ log .Error ("Failed to clone repository: %s (%v)" , repo .FullName (), err )
115
+ return fmt .Errorf ("Failed to clone repository: %s (%v)" , repo .FullName (), err )
116
+ }
112
117
113
- gitRepo , err := git .OpenRepository (basePath )
114
- if err != nil {
115
- log .Error ("Unable to open temporary repository: %s (%v)" , basePath , err )
116
- return fmt .Errorf ("Failed to open new temporary repository in: %s %v" , basePath , err )
117
- }
118
+ gitRepo , err := git .OpenRepository (basePath )
119
+ if err != nil {
120
+ log .Error ("Unable to open temporary repository: %s (%v)" , basePath , err )
121
+ return fmt .Errorf ("Failed to open new temporary repository in: %s %v" , basePath , err )
122
+ }
118
123
119
- if err = gitRepo .CreateBranch (branchName , oldBranchName ); err != nil {
120
- log .Error ("Unable to create branch: %s from %s. (%v)" , branchName , oldBranchName , err )
121
- return fmt .Errorf ("Unable to create branch: %s from %s. (%v)" , branchName , oldBranchName , err )
122
- }
124
+ if err = gitRepo .CreateBranch (branchName , oldBranchName ); err != nil {
125
+ log .Error ("Unable to create branch: %s from %s. (%v)" , branchName , oldBranchName , err )
126
+ return fmt .Errorf ("Unable to create branch: %s from %s. (%v)" , branchName , oldBranchName , err )
127
+ }
123
128
124
- if err = git .Push (basePath , git.PushOptions {
125
- Remote : "origin" ,
126
- Branch : branchName ,
127
- Env : PushingEnvironment (doer , repo ),
128
- }); err != nil {
129
- return fmt .Errorf ("Push: %v" , err )
130
- }
129
+ if err = git .Push (basePath , git.PushOptions {
130
+ Remote : "origin" ,
131
+ Branch : branchName ,
132
+ Env : PushingEnvironment (doer , repo ),
133
+ }); err != nil {
134
+ return fmt .Errorf ("Push: %v" , err )
135
+ }
131
136
132
- return nil
133
- })
137
+ return nil
134
138
}
135
139
136
140
// CreateNewBranchFromCommit creates a new repository branch
@@ -139,36 +143,40 @@ func (repo *Repository) CreateNewBranchFromCommit(doer *User, commit, branchName
139
143
if err := repo .CheckBranchName (branchName ); err != nil {
140
144
return err
141
145
}
142
- return WithTemporaryPath ("branch-maker" , func (basePath string ) error {
143
- if err := git .Clone (repo .RepoPath (), basePath , git.CloneRepoOptions {
144
- Bare : true ,
145
- Shared : true ,
146
- }); err != nil {
147
- log .Error ("Failed to clone repository: %s (%v)" , repo .FullName (), err )
148
- return fmt .Errorf ("Failed to clone repository: %s (%v)" , repo .FullName (), err )
149
- }
146
+ basePath , err := CreateTemporaryPath ("branch-maker" )
147
+ if err != nil {
148
+ return err
149
+ }
150
+ defer RemoveTemporaryPath (basePath )
151
+
152
+ if err := git .Clone (repo .RepoPath (), basePath , git.CloneRepoOptions {
153
+ Bare : true ,
154
+ Shared : true ,
155
+ }); err != nil {
156
+ log .Error ("Failed to clone repository: %s (%v)" , repo .FullName (), err )
157
+ return fmt .Errorf ("Failed to clone repository: %s (%v)" , repo .FullName (), err )
158
+ }
150
159
151
- gitRepo , err := git .OpenRepository (basePath )
152
- if err != nil {
153
- log .Error ("Unable to open temporary repository: %s (%v)" , basePath , err )
154
- return fmt .Errorf ("Failed to open new temporary repository in: %s %v" , basePath , err )
155
- }
160
+ gitRepo , err := git .OpenRepository (basePath )
161
+ if err != nil {
162
+ log .Error ("Unable to open temporary repository: %s (%v)" , basePath , err )
163
+ return fmt .Errorf ("Failed to open new temporary repository in: %s %v" , basePath , err )
164
+ }
156
165
157
- if err = gitRepo .CreateBranch (branchName , commit ); err != nil {
158
- log .Error ("Unable to create branch: %s from %s. (%v)" , branchName , commit , err )
159
- return fmt .Errorf ("Unable to create branch: %s from %s. (%v)" , branchName , commit , err )
160
- }
166
+ if err = gitRepo .CreateBranch (branchName , commit ); err != nil {
167
+ log .Error ("Unable to create branch: %s from %s. (%v)" , branchName , commit , err )
168
+ return fmt .Errorf ("Unable to create branch: %s from %s. (%v)" , branchName , commit , err )
169
+ }
161
170
162
- if err = git .Push (basePath , git.PushOptions {
163
- Remote : "origin" ,
164
- Branch : branchName ,
165
- Env : PushingEnvironment (doer , repo ),
166
- }); err != nil {
167
- return fmt .Errorf ("Push: %v" , err )
168
- }
171
+ if err = git .Push (basePath , git.PushOptions {
172
+ Remote : "origin" ,
173
+ Branch : branchName ,
174
+ Env : PushingEnvironment (doer , repo ),
175
+ }); err != nil {
176
+ return fmt .Errorf ("Push: %v" , err )
177
+ }
169
178
170
- return nil
171
- })
179
+ return nil
172
180
}
173
181
174
182
// GetCommit returns all the commits of a branch
0 commit comments