diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-11-02 18:53:20 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-11-02 18:53:20 -0400 |
commit | 7d5f4e73158cfc4837e6fe1ccf609c931c4f87b7 (patch) | |
tree | 8af98da31237013c251b9de490c4d88aa5755195 /src | |
parent | 1a7dd9bd692ff9db64cea670fa0feaa79c82706d (diff) |
views
Diffstat (limited to 'src')
-rw-r--r-- | src/edit/git.go | 9 | ||||
-rw-r--r-- | src/edit/posthack.go | 2 | ||||
-rw-r--r-- | src/edit/util.go | 18 | ||||
-rw-r--r-- | src/edit/views.go | 24 |
4 files changed, 46 insertions, 7 deletions
diff --git a/src/edit/git.go b/src/edit/git.go index 715a703..25d46cc 100644 --- a/src/edit/git.go +++ b/src/edit/git.go @@ -10,12 +10,17 @@ import ( "time" ) +// Use .Output() instead of .Run() so that it populates +// ExitError.Stderr. + func GitPull() error { - return exec.Command("git", "fetch").Run() + _, err := exec.Command("git", "fetch").Output() + return err } func GitPush() error { - return exec.Command("git", "push").Run() + _, err := exec.Command("git", "push").Output() + return err } type Edit struct { diff --git a/src/edit/posthack.go b/src/edit/posthack.go index 062903f..9e4759e 100644 --- a/src/edit/posthack.go +++ b/src/edit/posthack.go @@ -28,7 +28,7 @@ func PostHack(req *http.Request) { req.PostForm.Del("_message") } // _body - if file, header, err := req.FormFile("_body"); err != nil { + if file, header, err := req.FormFile("_body"); err == nil { req.Body = file for k, v := range header.Header { req.Header[k] = v diff --git a/src/edit/util.go b/src/edit/util.go index 519e46c..566796c 100644 --- a/src/edit/util.go +++ b/src/edit/util.go @@ -1,7 +1,25 @@ package main +import ( + "os/exec" +) + +type exitError exec.ExitError + +func (e *exitError) Error() string { + ret := e.ProcessState.String() + if len(e.Stderr) > 0 { + ret += "\n" + string(e.Stderr) + } + return ret +} + func errcheck(err error) { if err != nil { + if ee, ok := err.(*exec.ExitError); ok { + ee2 := exitError(*ee) + err = &ee2 + } panic(err) } } diff --git a/src/edit/views.go b/src/edit/views.go index d5ad985..81a6945 100644 --- a/src/edit/views.go +++ b/src/edit/views.go @@ -73,11 +73,27 @@ func renderViewBlob(w io.Writer, upath string, file GitFile) error { } func renderModified(w io.Writer, upath string) error { - // TODO - return nil + // Component render + var buf bytes.Buffer + err := tmplModified.Execute(&buf, map[string]string{ + "path": upath, + }) + if err != nil { + return err + } + // Page render + return renderPage(w, upath, "", buf.String()) } func renderDeleted(w io.Writer, upath string) error { - // TODO - return nil + // Component render + var buf bytes.Buffer + err := tmplDeleted.Execute(&buf, map[string]string{ + "path": upath, + }) + if err != nil { + return err + } + // Page render + return renderPage(w, upath, "", buf.String()) } |