summaryrefslogtreecommitdiffstats
path: root/models/wiki.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-03-04 13:32:17 -0500
committerUnknwon <u@gogs.io>2016-03-04 13:32:17 -0500
commit9df6ce48c538e0458b6798f0819db8afce43e5c7 (patch)
tree340f576bc4d0c4505edb40cbab2a2efd5cd66ac5 /models/wiki.go
parent4d5911dbcfc4aca28987e61dc46f0129010b6d29 (diff)
downloadgitea-9df6ce48c538e0458b6798f0819db8afce43e5c7.tar.gz
gitea-9df6ce48c538e0458b6798f0819db8afce43e5c7.zip
Minor fixes for #2746
Diffstat (limited to 'models/wiki.go')
-rw-r--r--models/wiki.go51
1 files changed, 25 insertions, 26 deletions
diff --git a/models/wiki.go b/models/wiki.go
index bf52df9b92..fee5a40814 100644
--- a/models/wiki.go
+++ b/models/wiki.go
@@ -7,12 +7,12 @@ package models
import (
"fmt"
"io/ioutil"
+ "net/url"
"os"
"path"
"path/filepath"
"strings"
"sync"
- "net/url"
"github.com/Unknwon/com"
@@ -116,6 +116,23 @@ func (repo *Repository) UpdateLocalWiki() error {
return updateLocalCopy(repo.WikiPath(), repo.LocalWikiPath())
}
+// discardLocalWikiChanges discards local commits make sure
+// it is even to remote branch when local copy exists.
+func discardLocalWikiChanges(localPath string) error {
+ if !com.IsExist(localPath) {
+ return nil
+ }
+ // No need to check if nothing in the repository.
+ if !git.IsBranchExist(localPath, "master") {
+ return nil
+ }
+
+ if err := git.ResetHEAD(localPath, true, "origin/master"); err != nil {
+ return fmt.Errorf("ResetHEAD: %v", err)
+ }
+ return nil
+}
+
// updateWikiPage adds new page to repository wiki.
func (repo *Repository) updateWikiPage(doer *User, oldTitle, title, content, message string, isNew bool) (err error) {
wikiWorkingPool.CheckIn(com.ToStr(repo.ID))
@@ -126,18 +143,9 @@ func (repo *Repository) updateWikiPage(doer *User, oldTitle, title, content, mes
}
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 {
+ if err = discardLocalWikiChanges(localPath); err != nil {
+ return fmt.Errorf("discardLocalWikiChanges: %v", err)
+ } else if err = repo.UpdateLocalWiki(); err != nil {
return fmt.Errorf("UpdateLocalWiki: %v", err)
}
@@ -184,23 +192,14 @@ func (repo *Repository) DeleteWikiPage(doer *User, title string) (err error) {
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 {
+ if err = discardLocalWikiChanges(localPath); err != nil {
+ return fmt.Errorf("discardLocalWikiChanges: %v", err)
+ } else if err = repo.UpdateLocalWiki(); err != nil {
return fmt.Errorf("UpdateLocalWiki: %v", err)
}
+ title = ToWikiPageName(strings.Replace(title, "/", " ", -1))
filename := path.Join(localPath, title+".md")
-
os.Remove(filename)
message := "Delete page '" + title + "'"