@@ -6,64 +6,11 @@ package models
6
6
7
7
import (
8
8
"fmt"
9
- "time"
10
9
11
10
"code.gitea.io/gitea/modules/git"
12
11
"code.gitea.io/gitea/modules/log"
13
- "code.gitea.io/gitea/modules/setting"
14
-
15
- "github.com/Unknwon/com"
16
12
)
17
13
18
- // checkoutNewBranch checks out to a new branch from the a branch name.
19
- func checkoutNewBranch (repoPath , localPath , oldBranch , newBranch string ) error {
20
- if err := git .Checkout (localPath , git.CheckoutOptions {
21
- Timeout : time .Duration (setting .Git .Timeout .Pull ) * time .Second ,
22
- Branch : newBranch ,
23
- OldBranch : oldBranch ,
24
- }); err != nil {
25
- return fmt .Errorf ("git checkout -b %s %s: %v" , newBranch , oldBranch , err )
26
- }
27
- return nil
28
- }
29
-
30
- // CheckoutNewBranch checks out a new branch
31
- func (repo * Repository ) CheckoutNewBranch (oldBranch , newBranch string ) error {
32
- return checkoutNewBranch (repo .RepoPath (), repo .LocalCopyPath (), oldBranch , newBranch )
33
- }
34
-
35
- // deleteLocalBranch deletes a branch from a local repo cache
36
- // First checks out default branch to avoid trying to delete the currently checked out branch
37
- func deleteLocalBranch (localPath , defaultBranch , deleteBranch string ) error {
38
- if ! com .IsExist (localPath ) {
39
- return nil
40
- }
41
-
42
- if ! git .IsBranchExist (localPath , deleteBranch ) {
43
- return nil
44
- }
45
-
46
- // Must NOT have branch currently checked out
47
- // Checkout default branch first
48
- if err := git .Checkout (localPath , git.CheckoutOptions {
49
- Timeout : time .Duration (setting .Git .Timeout .Pull ) * time .Second ,
50
- Branch : defaultBranch ,
51
- }); err != nil {
52
- return fmt .Errorf ("git checkout %s: %v" , defaultBranch , err )
53
- }
54
-
55
- cmd := git .NewCommand ("branch" )
56
- cmd .AddArguments ("-D" )
57
- cmd .AddArguments (deleteBranch )
58
- _ , err := cmd .RunInDir (localPath )
59
- return err
60
- }
61
-
62
- // DeleteLocalBranch deletes a branch from the local repo
63
- func (repo * Repository ) DeleteLocalBranch (branchName string ) error {
64
- return deleteLocalBranch (repo .LocalCopyPath (), repo .DefaultBranch , branchName )
65
- }
66
-
67
14
// Branch holds the branch information
68
15
type Branch struct {
69
16
Path string
@@ -186,39 +133,6 @@ func (repo *Repository) CreateNewBranch(doer *User, oldBranchName, branchName st
186
133
})
187
134
}
188
135
189
- // updateLocalCopyToCommit pulls latest changes of given commit from repoPath to localPath.
190
- // It creates a new clone if local copy does not exist.
191
- // This function checks out target commit by default, it is safe to assume subsequent
192
- // operations are operating against target commit when caller has confidence for no race condition.
193
- func updateLocalCopyToCommit (repoPath , localPath , commit string ) error {
194
- if ! com .IsExist (localPath ) {
195
- if err := git .Clone (repoPath , localPath , git.CloneRepoOptions {
196
- Timeout : time .Duration (setting .Git .Timeout .Clone ) * time .Second ,
197
- }); err != nil {
198
- return fmt .Errorf ("git clone: %v" , err )
199
- }
200
- } else {
201
- _ , err := git .NewCommand ("fetch" , "origin" ).RunInDir (localPath )
202
- if err != nil {
203
- return fmt .Errorf ("git fetch origin: %v" , err )
204
- }
205
- if err := git .ResetHEAD (localPath , true , "HEAD" ); err != nil {
206
- return fmt .Errorf ("git reset --hard HEAD: %v" , err )
207
- }
208
- }
209
- if err := git .Checkout (localPath , git.CheckoutOptions {
210
- Branch : commit ,
211
- }); err != nil {
212
- return fmt .Errorf ("git checkout %s: %v" , commit , err )
213
- }
214
- return nil
215
- }
216
-
217
- // updateLocalCopyToCommit makes sure local copy of repository is at given commit.
218
- func (repo * Repository ) updateLocalCopyToCommit (commit string ) error {
219
- return updateLocalCopyToCommit (repo .RepoPath (), repo .LocalCopyPath (), commit )
220
- }
221
-
222
136
// CreateNewBranchFromCommit creates a new repository branch
223
137
func (repo * Repository ) CreateNewBranchFromCommit (doer * User , commit , branchName string ) (err error ) {
224
138
// Check if branch name can be used
0 commit comments