Skip to content

Commit e1e49eb

Browse files
committed
disable branching for now #156
1 parent aa8d106 commit e1e49eb

File tree

8 files changed

+348
-345
lines changed

8 files changed

+348
-345
lines changed

adminifier/wiki-branch.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package adminifier
2+
3+
// working with multiple branches is disabled until go-git supports it officially
4+
// see: https://github.com/cooper/quiki/issues/156
5+
6+
// func handleSwitchBranch(wr *wikiRequest) {
7+
// branchName := strings.TrimPrefix(wr.r.URL.Path, wr.wikiRoot+"func/switch-branch/")
8+
// if branchName == "" {
9+
// wr.err = errors.New("no branch selected")
10+
// return
11+
// }
12+
13+
// // bad branch name
14+
// if !wiki.ValidBranchName(branchName) {
15+
// wr.err = errors.New("invalid branch name: " + branchName)
16+
// return
17+
// }
18+
19+
// // fetch the branch
20+
// _, wr.err = wr.wi.Branch(branchName)
21+
// if wr.err != nil {
22+
// return
23+
// }
24+
25+
// // set branch
26+
// sessMgr.Put(wr.r.Context(), "branch", branchName)
27+
28+
// // TODO: when this request is submitted by JS, the UI can just reload
29+
// // the current frame so the user stays on the same page, just in new branch
30+
31+
// // redirect back to dashboard
32+
// http.Redirect(wr.w, wr.r, wr.wikiRoot+"dashboard", http.StatusTemporaryRedirect)
33+
// }
34+
35+
// func handleCreateBranch(wr *wikiRequest) {
36+
37+
// // TODO: need a different version of parsePost that returns JSON errors
38+
// if !parsePost(wr.w, wr.r, "branch") {
39+
// return
40+
// }
41+
42+
// // bad branch name
43+
// branchName := wr.r.Form.Get("branch")
44+
// if !wiki.ValidBranchName(branchName) {
45+
// wr.err = errors.New("invalid branch name: " + branchName)
46+
// return
47+
// }
48+
49+
// // create or switch branches
50+
// _, err := wr.wi.NewBranch(branchName)
51+
// if err != nil {
52+
// wr.err = err
53+
// return
54+
// }
55+
// sessMgr.Put(wr.r.Context(), "branch", branchName)
56+
57+
// // redirect back to dashboard
58+
// http.Redirect(wr.w, wr.r, wr.wikiRoot+"dashboard", http.StatusTemporaryRedirect)
59+
// }
60+
61+
// // possibly switch wiki branches
62+
// func switchUserWiki(wr *wikiRequest, wi *webserver.WikiInfo) {
63+
// userWiki := wi
64+
// branchName := sessMgr.GetString(wr.r.Context(), "branch")
65+
// if branchName != "" {
66+
// branchWiki, err := wi.Branch(branchName)
67+
// if err != nil {
68+
// wr.err = err
69+
// return
70+
// }
71+
// userWiki = wi.Copy(branchWiki)
72+
// }
73+
// wr.wi = userWiki
74+
// }
75+
76+
// func handleSwitchBranchFrame(wr *wikiRequest) {
77+
// branches, err := wr.wi.BranchNames()
78+
// if err != nil {
79+
// wr.err = err
80+
// return
81+
// }
82+
// wr.dot = struct {
83+
// Branches []string
84+
// wikiTemplate
85+
// }{
86+
// Branches: branches,
87+
// wikiTemplate: getGenericTemplate(wr),
88+
// }
89+
// }

adminifier/wiki.go

Lines changed: 17 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
)
2020

2121
var wikiFrameHandlers = map[string]func(*wikiRequest){
22+
// "switch-branch": handleSwitchBranchFrame,
2223
"dashboard": handleDashboardFrame,
2324
"pages": handlePagesFrame,
2425
"pages/": handlePagesFrame,
@@ -31,14 +32,13 @@ var wikiFrameHandlers = map[string]func(*wikiRequest){
3132
"edit-page": handleEditPageFrame,
3233
"edit-category": handleEditCategoryFrame,
3334
"edit-model": handleEditModelFrame,
34-
"switch-branch": handleSwitchBranchFrame,
3535
"help": handleWikiHelpFrame,
3636
"help/": handleWikiHelpFrame,
3737
}
3838

3939
var wikiFuncHandlers = map[string]func(*wikiRequest){
40-
"switch-branch/": handleSwitchBranch,
41-
"create-branch": handleCreateBranch,
40+
// "switch-branch/": handleSwitchBranch,
41+
// "create-branch": handleCreateBranch,
4242
"write-page": handleWritePage,
4343
"write-model": handleWriteModel,
4444
"write-config": handleWriteWikiConfig,
@@ -146,12 +146,13 @@ func setupWikiHandlers(shortcode string, wi *webserver.WikiInfo) {
146146
}
147147
dot = wr
148148

149-
// possibly switch wikis
150-
switchUserWiki(wr, wi)
151-
if wr.err != nil {
152-
// FIXME: don't panic
153-
panic(wr.err)
154-
}
149+
wr.wi = wi
150+
// DISABLED: possibly switch wikis
151+
// switchUserWiki(wr, wi)
152+
// if wr.err != nil {
153+
// // FIXME: don't panic
154+
// panic(wr.err)
155+
// }
155156

156157
// call handler
157158
handler(wr)
@@ -210,12 +211,13 @@ func setupWikiHandlers(shortcode string, wi *webserver.WikiInfo) {
210211
r: r,
211212
}
212213

213-
// possibly switch wikis
214-
switchUserWiki(wr, wi)
215-
if wr.err != nil {
216-
// FIXME: don't panic
217-
panic(wr.err)
218-
}
214+
wr.wi = wi
215+
// DISABLED: possibly switch wikis
216+
// switchUserWiki(wr, wi)
217+
// if wr.err != nil {
218+
// // FIXME: don't panic
219+
// panic(wr.err)
220+
// }
219221

220222
// call handler
221223
handler(wr)
@@ -520,76 +522,6 @@ func handleEditor(wr *wikiRequest, path, file, title string, o editorOpts) {
520522
}
521523
}
522524

523-
func handleSwitchBranchFrame(wr *wikiRequest) {
524-
branches, err := wr.wi.BranchNames()
525-
if err != nil {
526-
wr.err = err
527-
return
528-
}
529-
wr.dot = struct {
530-
Branches []string
531-
wikiTemplate
532-
}{
533-
Branches: branches,
534-
wikiTemplate: getGenericTemplate(wr),
535-
}
536-
}
537-
538-
func handleSwitchBranch(wr *wikiRequest) {
539-
branchName := strings.TrimPrefix(wr.r.URL.Path, wr.wikiRoot+"func/switch-branch/")
540-
if branchName == "" {
541-
wr.err = errors.New("no branch selected")
542-
return
543-
}
544-
545-
// bad branch name
546-
if !wiki.ValidBranchName(branchName) {
547-
wr.err = errors.New("invalid branch name: " + branchName)
548-
return
549-
}
550-
551-
// fetch the branch
552-
_, wr.err = wr.wi.Branch(branchName)
553-
if wr.err != nil {
554-
return
555-
}
556-
557-
// set branch
558-
sessMgr.Put(wr.r.Context(), "branch", branchName)
559-
560-
// TODO: when this request is submitted by JS, the UI can just reload
561-
// the current frame so the user stays on the same page, just in new branch
562-
563-
// redirect back to dashboard
564-
http.Redirect(wr.w, wr.r, wr.wikiRoot+"dashboard", http.StatusTemporaryRedirect)
565-
}
566-
567-
func handleCreateBranch(wr *wikiRequest) {
568-
569-
// TODO: need a different version of parsePost that returns JSON errors
570-
if !parsePost(wr.w, wr.r, "branch") {
571-
return
572-
}
573-
574-
// bad branch name
575-
branchName := wr.r.Form.Get("branch")
576-
if !wiki.ValidBranchName(branchName) {
577-
wr.err = errors.New("invalid branch name: " + branchName)
578-
return
579-
}
580-
581-
// create or switch branches
582-
_, err := wr.wi.NewBranch(branchName)
583-
if err != nil {
584-
wr.err = err
585-
return
586-
}
587-
sessMgr.Put(wr.r.Context(), "branch", branchName)
588-
589-
// redirect back to dashboard
590-
http.Redirect(wr.w, wr.r, wr.wikiRoot+"dashboard", http.StatusTemporaryRedirect)
591-
}
592-
593525
func handleWritePage(wr *wikiRequest) {
594526
if !parsePost(wr.w, wr.r, "name", "content") {
595527
return
@@ -795,21 +727,6 @@ func handleCreate(typ string, wr *wikiRequest, createFunc func(dir, title string
795727
http.Redirect(wr.w, wr.r, wr.wikiRoot+"edit-"+typ+"?page="+path.Join(dir, filename), http.StatusTemporaryRedirect)
796728
}
797729

798-
// possibly switch wiki branches
799-
func switchUserWiki(wr *wikiRequest, wi *webserver.WikiInfo) {
800-
userWiki := wi
801-
branchName := sessMgr.GetString(wr.r.Context(), "branch")
802-
if branchName != "" {
803-
branchWiki, err := wi.Branch(branchName)
804-
if err != nil {
805-
wr.err = err
806-
return
807-
}
808-
userWiki = wi.Copy(branchWiki)
809-
}
810-
wr.wi = userWiki
811-
}
812-
813730
func getGenericTemplate(wr *wikiRequest) wikiTemplate {
814731

815732
// prepend external root to all wiki roots

go.mod

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,43 @@ require (
99
github.com/alecthomas/chroma/v2 v2.15.0
1010
github.com/alexedwards/scs/v2 v2.8.0
1111
github.com/cooper/ferret-chroma v0.0.0-20201209083634-9d9918e49841
12-
github.com/cooper/go-git/v4 v4.14.1
1312
github.com/cooper/imaging v1.0.0
1413
github.com/enescakir/emoji v1.0.0
1514
github.com/fsnotify/fsnotify v1.8.0
15+
github.com/go-git/go-git/v5 v5.14.0
1616
github.com/grokify/html-strip-tags-go v0.1.0
1717
github.com/pkg/errors v0.9.1
1818
github.com/russross/blackfriday/v2 v2.1.0
1919
github.com/whyrusleeping/hellabot v0.0.0-20191113145436-fd8fa1922281
20-
golang.org/x/crypto v0.31.0
21-
gopkg.in/src-d/go-billy.v4 v4.3.2
20+
golang.org/x/crypto v0.35.0
2221
)
2322

2423
require (
24+
dario.cat/mergo v1.0.0 // indirect
2525
github.com/Microsoft/go-winio v0.6.2 // indirect
26+
github.com/ProtonMail/go-crypto v1.1.5 // indirect
2627
github.com/alecthomas/chroma v0.10.0 // indirect
28+
github.com/cloudflare/circl v1.6.0 // indirect
29+
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
2730
github.com/dlclark/regexp2 v1.11.4 // indirect
2831
github.com/emirpasic/gods v1.18.1 // indirect
32+
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
33+
github.com/go-git/go-billy/v5 v5.6.2 // indirect
2934
github.com/go-stack/stack v1.8.0 // indirect
30-
github.com/google/go-cmp v0.6.0 // indirect
35+
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
3136
github.com/inconshreveable/log15 v0.0.0-20200109203555-b30bc20e4fd1 // indirect
3237
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
3338
github.com/kevinburke/ssh_config v1.2.0 // indirect
3439
github.com/mattn/go-colorable v0.0.9 // indirect
3540
github.com/mattn/go-isatty v0.0.4 // indirect
36-
github.com/mitchellh/go-homedir v1.1.0 // indirect
3741
github.com/mudler/sendfd v0.0.0-20150620134918-f0fc74c13877 // indirect
38-
github.com/sergi/go-diff v1.3.1 // indirect
39-
github.com/src-d/gcfg v1.4.0 // indirect
42+
github.com/pjbgf/sha1cd v0.3.2 // indirect
43+
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
44+
github.com/skeema/knownhosts v1.3.1 // indirect
4045
github.com/xanzy/ssh-agent v0.3.3 // indirect
4146
golang.org/x/image v0.23.0 // indirect
42-
golang.org/x/net v0.33.0 // indirect
43-
golang.org/x/sys v0.28.0 // indirect
47+
golang.org/x/net v0.35.0 // indirect
48+
golang.org/x/sys v0.30.0 // indirect
4449
gopkg.in/inconshreveable/log15.v2 v2.0.0-20200109203555-b30bc20e4fd1 // indirect
4550
gopkg.in/sorcix/irc.v1 v1.1.4 // indirect
4651
gopkg.in/warnings.v0 v0.1.2 // indirect

0 commit comments

Comments
 (0)