diff options
author | Unknwon <u@gogs.io> | 2016-03-04 13:14:37 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2016-03-04 13:14:37 -0500 |
commit | 4d5911dbcfc4aca28987e61dc46f0129010b6d29 (patch) | |
tree | 9f9fa240af57e270d0fa490d68a3d75ef3c9d1c8 /models | |
parent | d57a2b908ab0954568b0ac5f1030c454a944bee1 (diff) | |
parent | 2f228ddf31b76bc424635f262f34e4b01226f2ef (diff) | |
download | gitea-4d5911dbcfc4aca28987e61dc46f0129010b6d29.tar.gz gitea-4d5911dbcfc4aca28987e61dc46f0129010b6d29.zip |
Merge pull request #2746 from joshfng/feature-delete-wiki-pages
Add ability to delete single wiki pages.
Diffstat (limited to 'models')
-rw-r--r-- | models/wiki.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/models/wiki.go b/models/wiki.go index e3eb1f6807..bf52df9b92 100644 --- a/models/wiki.go +++ b/models/wiki.go @@ -178,3 +178,40 @@ func (repo *Repository) AddWikiPage(doer *User, title, content, message string) func (repo *Repository) EditWikiPage(doer *User, oldTitle, title, content, message string) error { return repo.updateWikiPage(doer, oldTitle, title, content, message, false) } + +func (repo *Repository) DeleteWikiPage(doer *User, title string) (err error) { + wikiWorkingPool.CheckIn(com.ToStr(repo.ID)) + defer wikiWorkingPool.CheckOut(com.ToStr(repo.ID)) + + localPath := repo.LocalWikiPath() + + // Discard local commits make sure even to remote when local copy exists. + if com.IsExist(localPath) { + // No need to check if nothing in the repository. + if git.IsBranchExist(localPath, "master") { + if err = git.ResetHEAD(localPath, true, "origin/master"); err != nil { + return fmt.Errorf("Reset: %v", err) + } + } + } + + if err = repo.UpdateLocalWiki(); err != nil { + return fmt.Errorf("UpdateLocalWiki: %v", err) + } + + filename := path.Join(localPath, title+".md") + + os.Remove(filename) + + message := "Delete page '" + title + "'" + + if err = git.AddChanges(localPath, true); err != nil { + return fmt.Errorf("AddChanges: %v", err) + } else if err = git.CommitChanges(localPath, message, doer.NewGitSig()); err != nil { + return fmt.Errorf("CommitChanges: %v", err) + } else if err = git.Push(localPath, "origin", "master"); err != nil { + return fmt.Errorf("Push: %v", err) + } + + return nil +} |