@@ -7,12 +7,12 @@ package models
7
7
import (
8
8
"fmt"
9
9
"io/ioutil"
10
+ "net/url"
10
11
"os"
11
12
"path"
12
13
"path/filepath"
13
14
"strings"
14
15
"sync"
15
- "net/url"
16
16
17
17
"github.com/Unknwon/com"
18
18
@@ -116,6 +116,23 @@ func (repo *Repository) UpdateLocalWiki() error {
116
116
return updateLocalCopy (repo .WikiPath (), repo .LocalWikiPath ())
117
117
}
118
118
119
+ // discardLocalWikiChanges discards local commits make sure
120
+ // it is even to remote branch when local copy exists.
121
+ func discardLocalWikiChanges (localPath string ) error {
122
+ if ! com .IsExist (localPath ) {
123
+ return nil
124
+ }
125
+ // No need to check if nothing in the repository.
126
+ if ! git .IsBranchExist (localPath , "master" ) {
127
+ return nil
128
+ }
129
+
130
+ if err := git .ResetHEAD (localPath , true , "origin/master" ); err != nil {
131
+ return fmt .Errorf ("ResetHEAD: %v" , err )
132
+ }
133
+ return nil
134
+ }
135
+
119
136
// updateWikiPage adds new page to repository wiki.
120
137
func (repo * Repository ) updateWikiPage (doer * User , oldTitle , title , content , message string , isNew bool ) (err error ) {
121
138
wikiWorkingPool .CheckIn (com .ToStr (repo .ID ))
@@ -126,18 +143,9 @@ func (repo *Repository) updateWikiPage(doer *User, oldTitle, title, content, mes
126
143
}
127
144
128
145
localPath := repo .LocalWikiPath ()
129
-
130
- // Discard local commits make sure even to remote when local copy exists.
131
- if com .IsExist (localPath ) {
132
- // No need to check if nothing in the repository.
133
- if git .IsBranchExist (localPath , "master" ) {
134
- if err = git .ResetHEAD (localPath , true , "origin/master" ); err != nil {
135
- return fmt .Errorf ("Reset: %v" , err )
136
- }
137
- }
138
- }
139
-
140
- if err = repo .UpdateLocalWiki (); err != nil {
146
+ if err = discardLocalWikiChanges (localPath ); err != nil {
147
+ return fmt .Errorf ("discardLocalWikiChanges: %v" , err )
148
+ } else if err = repo .UpdateLocalWiki (); err != nil {
141
149
return fmt .Errorf ("UpdateLocalWiki: %v" , err )
142
150
}
143
151
@@ -184,23 +192,14 @@ func (repo *Repository) DeleteWikiPage(doer *User, title string) (err error) {
184
192
defer wikiWorkingPool .CheckOut (com .ToStr (repo .ID ))
185
193
186
194
localPath := repo .LocalWikiPath ()
187
-
188
- // Discard local commits make sure even to remote when local copy exists.
189
- if com .IsExist (localPath ) {
190
- // No need to check if nothing in the repository.
191
- if git .IsBranchExist (localPath , "master" ) {
192
- if err = git .ResetHEAD (localPath , true , "origin/master" ); err != nil {
193
- return fmt .Errorf ("Reset: %v" , err )
194
- }
195
- }
196
- }
197
-
198
- if err = repo .UpdateLocalWiki (); err != nil {
195
+ if err = discardLocalWikiChanges (localPath ); err != nil {
196
+ return fmt .Errorf ("discardLocalWikiChanges: %v" , err )
197
+ } else if err = repo .UpdateLocalWiki (); err != nil {
199
198
return fmt .Errorf ("UpdateLocalWiki: %v" , err )
200
199
}
201
200
201
+ title = ToWikiPageName (strings .Replace (title , "/" , " " , - 1 ))
202
202
filename := path .Join (localPath , title + ".md" )
203
-
204
203
os .Remove (filename )
205
204
206
205
message := "Delete page '" + title + "'"
0 commit comments