aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-11-27 01:50:38 -0500
committerUnknwon <u@gogs.io>2015-11-27 01:50:38 -0500
commite42fcb033d4a7ee44fe397be3e933d7031b7d8f7 (patch)
treea203fff39c92f947c4585a746e2345b3ebc67b3c /models
parent392f3ee21016476fb9794f78882d6c447acb8449 (diff)
downloadgitea-e42fcb033d4a7ee44fe397be3e933d7031b7d8f7.tar.gz
gitea-e42fcb033d4a7ee44fe397be3e933d7031b7d8f7.zip
wiki: finish edit
Diffstat (limited to 'models')
-rw-r--r--models/error.go20
-rw-r--r--models/pull.go2
-rw-r--r--models/wiki.go25
3 files changed, 43 insertions, 4 deletions
diff --git a/models/error.go b/models/error.go
index 069346bef3..d005b9af73 100644
--- a/models/error.go
+++ b/models/error.go
@@ -107,6 +107,26 @@ func (err ErrUserHasOrgs) Error() string {
return fmt.Sprintf("user still has membership of organizations [uid: %d]", err.UID)
}
+// __ __.__ __ .__
+// / \ / \__| | _|__|
+// \ \/\/ / | |/ / |
+// \ /| | <| |
+// \__/\ / |__|__|_ \__|
+// \/ \/
+
+type ErrWikiAlreadyExist struct {
+ Title string
+}
+
+func IsErrWikiAlreadyExist(err error) bool {
+ _, ok := err.(ErrWikiAlreadyExist)
+ return ok
+}
+
+func (err ErrWikiAlreadyExist) Error() string {
+ return fmt.Sprintf("wiki page already exists [title: %s]", err.Title)
+}
+
// __________ ___. .__ .__ ____ __.
// \______ \__ _\_ |__ | | |__| ____ | |/ _|____ ___.__.
// | ___/ | \ __ \| | | |/ ___\ | <_/ __ < | |
diff --git a/models/pull.go b/models/pull.go
index 080819cb04..8020a1e1e7 100644
--- a/models/pull.go
+++ b/models/pull.go
@@ -252,7 +252,7 @@ func (pr *PullRequest) testPatch() (err error) {
// Checkout base branch.
_, stderr, err := process.ExecDir(-1, pr.BaseRepo.LocalCopyPath(),
- fmt.Sprintf("PullRequest.Merge(git checkout): %s", pr.BaseRepo.ID),
+ fmt.Sprintf("PullRequest.Merge(git checkout): %v", pr.BaseRepo.ID),
"git", "checkout", pr.BaseBranch)
if err != nil {
return fmt.Errorf("git checkout: %s", stderr)
diff --git a/models/wiki.go b/models/wiki.go
index d78c51a88d..fd84ce4457 100644
--- a/models/wiki.go
+++ b/models/wiki.go
@@ -7,6 +7,7 @@ package models
import (
"fmt"
"io/ioutil"
+ "os"
"path"
"path/filepath"
"strings"
@@ -108,8 +109,8 @@ func (repo *Repository) UpdateLocalWiki() error {
return updateLocalCopy(repo.WikiPath(), repo.LocalWikiPath())
}
-// AddWikiPage adds new page to repository wiki.
-func (repo *Repository) AddWikiPage(doer *User, title, content, message string) (err error) {
+// 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))
defer wikiWorkingPool.CheckOut(com.ToStr(repo.ID))
@@ -133,8 +134,18 @@ func (repo *Repository) AddWikiPage(doer *User, title, content, message string)
return fmt.Errorf("UpdateLocalWiki: %v", err)
}
- title = strings.Replace(title, "/", " ", -1)
+ title = ToWikiPageName(strings.Replace(title, "/", " ", -1))
filename := path.Join(localPath, title+".md")
+
+ // If not a new file, show perform update not create.
+ if isNew {
+ if com.IsExist(filename) {
+ return ErrWikiAlreadyExist{filename}
+ }
+ } else {
+ os.Remove(path.Join(localPath, oldTitle+".md"))
+ }
+
if err = ioutil.WriteFile(filename, []byte(content), 0666); err != nil {
return fmt.Errorf("WriteFile: %v", err)
}
@@ -152,3 +163,11 @@ func (repo *Repository) AddWikiPage(doer *User, title, content, message string)
return nil
}
+
+func (repo *Repository) AddWikiPage(doer *User, title, content, message string) error {
+ return repo.updateWikiPage(doer, "", title, content, message, true)
+}
+
+func (repo *Repository) EditWikiPage(doer *User, oldTitle, title, content, message string) error {
+ return repo.updateWikiPage(doer, oldTitle, title, content, message, false)
+}