Skip to content

Commit c6419be

Browse files
committed
Remove the last LocalRepo helpers
1 parent 2ffa506 commit c6419be

File tree

2 files changed

+0
-123
lines changed

2 files changed

+0
-123
lines changed

models/repo.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -735,43 +735,6 @@ func (repo *Repository) LocalCopyPath() string {
735735
return path.Join(LocalCopyPath(), com.ToStr(repo.ID))
736736
}
737737

738-
// UpdateLocalCopyBranch pulls latest changes of given branch from repoPath to localPath.
739-
// It creates a new clone if local copy does not exist.
740-
// This function checks out target branch by default, it is safe to assume subsequent
741-
// operations are operating against target branch when caller has confidence for no race condition.
742-
func UpdateLocalCopyBranch(repoPath, localPath, branch string) error {
743-
if !com.IsExist(localPath) {
744-
if err := git.Clone(repoPath, localPath, git.CloneRepoOptions{
745-
Timeout: time.Duration(setting.Git.Timeout.Clone) * time.Second,
746-
Branch: branch,
747-
}); err != nil {
748-
return fmt.Errorf("git clone %s: %v", branch, err)
749-
}
750-
} else {
751-
_, err := git.NewCommand("fetch", "origin").RunInDir(localPath)
752-
if err != nil {
753-
return fmt.Errorf("git fetch origin: %v", err)
754-
}
755-
if len(branch) > 0 {
756-
if err := git.Checkout(localPath, git.CheckoutOptions{
757-
Branch: branch,
758-
}); err != nil {
759-
return fmt.Errorf("git checkout %s: %v", branch, err)
760-
}
761-
762-
if err := git.ResetHEAD(localPath, true, "origin/"+branch); err != nil {
763-
return fmt.Errorf("git reset --hard origin/%s: %v", branch, err)
764-
}
765-
}
766-
}
767-
return nil
768-
}
769-
770-
// UpdateLocalCopyBranch makes sure local copy of repository in given branch is up-to-date.
771-
func (repo *Repository) UpdateLocalCopyBranch(branch string) error {
772-
return UpdateLocalCopyBranch(repo.RepoPath(), repo.LocalCopyPath(), branch)
773-
}
774-
775738
// PatchPath returns corresponding patch file path of repository by given issue ID.
776739
func (repo *Repository) PatchPath(index int64) (string, error) {
777740
return repo.patchPath(x, index)

models/repo_branch.go

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -6,64 +6,11 @@ package models
66

77
import (
88
"fmt"
9-
"time"
109

1110
"code.gitea.io/gitea/modules/git"
1211
"code.gitea.io/gitea/modules/log"
13-
"code.gitea.io/gitea/modules/setting"
14-
15-
"github.com/Unknwon/com"
1612
)
1713

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-
6714
// Branch holds the branch information
6815
type Branch struct {
6916
Path string
@@ -186,39 +133,6 @@ func (repo *Repository) CreateNewBranch(doer *User, oldBranchName, branchName st
186133
})
187134
}
188135

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-
222136
// CreateNewBranchFromCommit creates a new repository branch
223137
func (repo *Repository) CreateNewBranchFromCommit(doer *User, commit, branchName string) (err error) {
224138
// Check if branch name can be used

0 commit comments

Comments
 (0)