Skip to content

Commit 2f8ec3d

Browse files
committed
Move branch checkout functions out of repo_editor.go as they are no longer used there
1 parent c4fde84 commit 2f8ec3d

File tree

2 files changed

+40
-40
lines changed

2 files changed

+40
-40
lines changed

models/repo_branch.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,46 @@ import (
1414
"github.com/Unknwon/com"
1515
)
1616

17+
// discardLocalRepoBranchChanges discards local commits/changes of
18+
// given branch to make sure it is even to remote branch.
19+
func discardLocalRepoBranchChanges(localPath, branch string) error {
20+
if !com.IsExist(localPath) {
21+
return nil
22+
}
23+
// No need to check if nothing in the repository.
24+
if !git.IsBranchExist(localPath, branch) {
25+
return nil
26+
}
27+
28+
refName := "origin/" + branch
29+
if err := git.ResetHEAD(localPath, true, refName); err != nil {
30+
return fmt.Errorf("git reset --hard %s: %v", refName, err)
31+
}
32+
return nil
33+
}
34+
35+
// DiscardLocalRepoBranchChanges discards the local repository branch changes
36+
func (repo *Repository) DiscardLocalRepoBranchChanges(branch string) error {
37+
return discardLocalRepoBranchChanges(repo.LocalCopyPath(), branch)
38+
}
39+
40+
// checkoutNewBranch checks out to a new branch from the a branch name.
41+
func checkoutNewBranch(repoPath, localPath, oldBranch, newBranch string) error {
42+
if err := git.Checkout(localPath, git.CheckoutOptions{
43+
Timeout: time.Duration(setting.Git.Timeout.Pull) * time.Second,
44+
Branch: newBranch,
45+
OldBranch: oldBranch,
46+
}); err != nil {
47+
return fmt.Errorf("git checkout -b %s %s: %v", newBranch, oldBranch, err)
48+
}
49+
return nil
50+
}
51+
52+
// CheckoutNewBranch checks out a new branch
53+
func (repo *Repository) CheckoutNewBranch(oldBranch, newBranch string) error {
54+
return checkoutNewBranch(repo.RepoPath(), repo.LocalCopyPath(), oldBranch, newBranch)
55+
}
56+
1757
// Branch holds the branch information
1858
type Branch struct {
1959
Path string

models/repo_editor.go

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -32,46 +32,6 @@ import (
3232
// /_______ /\____ | |__||__| \___ / |__|____/\___ >
3333
// \/ \/ \/ \/
3434

35-
// discardLocalRepoBranchChanges discards local commits/changes of
36-
// given branch to make sure it is even to remote branch.
37-
func discardLocalRepoBranchChanges(localPath, branch string) error {
38-
if !com.IsExist(localPath) {
39-
return nil
40-
}
41-
// No need to check if nothing in the repository.
42-
if !git.IsBranchExist(localPath, branch) {
43-
return nil
44-
}
45-
46-
refName := "origin/" + branch
47-
if err := git.ResetHEAD(localPath, true, refName); err != nil {
48-
return fmt.Errorf("git reset --hard %s: %v", refName, err)
49-
}
50-
return nil
51-
}
52-
53-
// DiscardLocalRepoBranchChanges discards the local repository branch changes
54-
func (repo *Repository) DiscardLocalRepoBranchChanges(branch string) error {
55-
return discardLocalRepoBranchChanges(repo.LocalCopyPath(), branch)
56-
}
57-
58-
// checkoutNewBranch checks out to a new branch from the a branch name.
59-
func checkoutNewBranch(repoPath, localPath, oldBranch, newBranch string) error {
60-
if err := git.Checkout(localPath, git.CheckoutOptions{
61-
Timeout: time.Duration(setting.Git.Timeout.Pull) * time.Second,
62-
Branch: newBranch,
63-
OldBranch: oldBranch,
64-
}); err != nil {
65-
return fmt.Errorf("git checkout -b %s %s: %v", newBranch, oldBranch, err)
66-
}
67-
return nil
68-
}
69-
70-
// CheckoutNewBranch checks out a new branch
71-
func (repo *Repository) CheckoutNewBranch(oldBranch, newBranch string) error {
72-
return checkoutNewBranch(repo.RepoPath(), repo.LocalCopyPath(), oldBranch, newBranch)
73-
}
74-
7535
// UpdateRepoFileOptions holds the repository file update options
7636
type UpdateRepoFileOptions struct {
7737
LastCommitID string

0 commit comments

Comments
 (0)