@@ -178,3 +178,40 @@ func (repo *Repository) AddWikiPage(doer *User, title, content, message string)
178
178
func (repo * Repository ) EditWikiPage (doer * User , oldTitle , title , content , message string ) error {
179
179
return repo .updateWikiPage (doer , oldTitle , title , content , message , false )
180
180
}
181
+
182
+ func (repo * Repository ) DeleteWikiPage (doer * User , title string ) (err error ) {
183
+ wikiWorkingPool .CheckIn (com .ToStr (repo .ID ))
184
+ defer wikiWorkingPool .CheckOut (com .ToStr (repo .ID ))
185
+
186
+ 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 {
199
+ return fmt .Errorf ("UpdateLocalWiki: %v" , err )
200
+ }
201
+
202
+ filename := path .Join (localPath , title + ".md" )
203
+
204
+ os .Remove (filename )
205
+
206
+ message := "Delete page '" + title + "'"
207
+
208
+ if err = git .AddChanges (localPath , true ); err != nil {
209
+ return fmt .Errorf ("AddChanges: %v" , err )
210
+ } else if err = git .CommitChanges (localPath , message , doer .NewGitSig ()); err != nil {
211
+ return fmt .Errorf ("CommitChanges: %v" , err )
212
+ } else if err = git .Push (localPath , "origin" , "master" ); err != nil {
213
+ return fmt .Errorf ("Push: %v" , err )
214
+ }
215
+
216
+ return nil
217
+ }
0 commit comments