MCPcopy Create free account
hub / github.com/gogs/gogs / discardLocalRepoBranchChanges

Function discardLocalRepoBranchChanges

internal/database/repo_editor.go:87–102  ·  view source on GitHub ↗

___________ .___.__ __ ___________.__.__ \_ _____/ __| _/|__|/ |_ \_ _____/|__| | ____ | __)_ / __ | | \ __\ | __) | | | _/ __ \ | \/ /_/ | | || | | \ | | |_\ ___/ _______ /\____ | |__||__| \___ / |__|____/\___ > \/ \/

(localPath, branch string)

Source from the content-addressed store, hash-verified

85// discardLocalRepoBranchChanges discards local commits/changes of
86// given branch to make sure it is even to remote branch.
87func discardLocalRepoBranchChanges(localPath, branch string) error {
88 if !com.IsExist(localPath) {
89 return nil
90 }
91
92 // No need to check if nothing in the repository.
93 if !git.RepoHasBranch(localPath, branch) {
94 return nil
95 }
96
97 rev := "origin/" + branch
98 if err := git.Reset(localPath, rev, git.ResetOptions{Hard: true}); err != nil {
99 return errors.Newf("reset [revision: %s]: %v", rev, err)
100 }
101 return nil
102}
103
104func (r *Repository) DiscardLocalRepoBranchChanges(branch string) error {
105 return discardLocalRepoBranchChanges(r.LocalCopyPath(), branch)

Callers 3

discardLocalWikiChangesFunction · 0.85
CreateNewBranchMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected